Android 4.x RemoteControlClient.setTransportControlFlags() not working?
Asked Answered
T

2

9

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.

Tidewaiter answered 15/3, 2012 at 14:22 Comment(2)
I've noticed the same issue with the previous button, and there doesn't seem to be a way around it. For FLAG_KEY_MEDIA_PLAY_PAUSE, FLAG_KEY_MEDIA_STOP and KEYCODE_MEDIA_PLAY, it seems FLAG_KEY_MEDIA_PLAY_PAUSE is always used no matter what you specify. However, it should be expected to receive KEYCODE_MEDIA_PLAY_PAUSE from FLAG_KEY_MEDIA_PLAY_PAUSE. If it worked as it should, you'd want to specify FLAG_KEY_MEDIA_PLAY to receive KEYCODE_MEDIA_PLAY.Sams
See code.google.com/p/android/issues/detail?id=29920 for the wrong media buttons.Boltzmann
A
0

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.

Abeyance answered 8/4, 2014 at 7:14 Comment(0)
A
0

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

Abuzz answered 24/10, 2014 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.