android - Weird blinking on the lock screen remote control client when stopping it from the client itself -
i'm building streaming android app , i'm trying integrate remote control client (to have example control lock screen on ics+).
to so, i'm doing @ start in streaming service:
int result = audiomanager.requestaudiofocus(this, audiomanager.stream_music, audiomanager.audiofocus_gain); if (result != audiomanager.audiofocus_request_granted) { stopself(); } mediabuttonreceivercomponent = new componentname(this, remotecontrolreceiver.class); audiomanager.registermediabuttoneventreceiver(mediabuttonreceivercomponent); if (remotecontrolclientcompat == null) { final intent mediabuttonintent = new intent(intent.action_media_button); mediabuttonintent.setcomponent(mediabuttonreceivercomponent); remotecontrolclientcompat = new remotecontrolclientcompat( pendingintent.getbroadcast( getapplicationcontext(), 0, mediabuttonintent, pendingintent.flag_update_current ) ); remotecontrolhelper.registerremotecontrolclient(audiomanager, remotecontrolclientcompat); } final int flags = remotecontrolclient.flag_key_media_stop; remotecontrolclientcompat.settransportcontrolflags(flags);
remotecontrolclientcompat
instance of remotecontrolclientcompat samples.
then during streaming i'm updating metadata. working normally, controls sent remotecontrolreceiver
. data , image appear nicely on lock screen.
stopping streaming app destroys lock screen thing when i'm trying destroy widget (by pressing stop button), it's doing weird. pressing stop button makes broadcast receiver stop streaming service. in service's ondestroy() method, i'm doing that:
remotecontrolhelper.unregisterremotecontrolclient(audiomanager, remotecontrolclientcompat); audiomanager.unregistermediabuttoneventreceiver(mediabuttonreceivercomponent); audiomanager.abandonaudiofocus(this);
the widget goes blinking audiomanager.unregistermediabuttoneventreceiver(mediabuttonreceivercomponent);
called. i've tried commenting line , blinking happens audiomanager.abandonaudiofocus(this);
. commenting other line makes blink when service stops.
i've noticed happens when i'm stopping streaming notification.
what doing wrong? tried changing order of calls couldn't solve it. i've notice spotify had exact same issue couple of versions ago. i'm wondering how solved it...
ok fixed it. it's because remotecontrolclient cannot playing when abandon audio focus. had call before destroying anything:
remotecontrolclientcompat.setplaybackstate(remotecontrolclient.playstate_paused);
Comments
Post a Comment