Android 4.x RemoteControlClient.setTransportControlFlags() not working?

夙愿已清 提交于 2019-12-21 04:04:41

问题


I'm trying to use the RemoteControlClient class to support the lock screen player with my app. One issue is that setting the transport control flags seems like they don't work properly.

For example I'm trying to just show a play/stop icon no prev/next:

mRemoteControlClient.setTransportControlFlags(
                        RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
                        RemoteControlClient.FLAG_KEY_MEDIA_STOP);

This shows a previous icon and pause icon! Why?

To make things even worse when pressing the stop/play button you only receive KEYCODE_MEDIA_PLAY_PAUSE when you should be getting KEYCODE_MEDIA_STOP or KEYCODE_MEDIA_PLAY.

This is frustrating poor development on Android side if I find out I'm doing this correctly.


回答1:


The FLAG_KEY_MEDIA_STOP never shows stop because of bug in android as reported here: https://code.google.com/p/android/issues/detail?id=29920

If you use the flag PLAY_PAUSE is should not produce a KEYCODE_MEDIA_STOP event. Why would it? It is a play/pause toggle action that does what it is intended to. It is up to your application to store the state of your media player.

If I understand the documentation correctly you could get KEYCODE_MEDIA_PLAY or KEYCODE_MEDIA_PAUSE only if you use the flags FLAG_KEY_MEDIA_PLAY and FLAG_KEY_MEDIA_PAUSE. But android might be "clever" and translate it to a toggle. I'm not sure about that.




回答2:


Use the FLAG_KEY_MEDIA_PLAY_PAUSE

oRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE);

And lie to the RemoteControlClient ;-)

Tell him the stream is buffering and it will show the stop button!

oRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);

Cheers



来源:https://stackoverflow.com/questions/9721695/android-4-x-remotecontrolclient-settransportcontrolflags-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!