Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to make fastforward/rewind buttons visible in compact notification mode #7733

Open
ravisaini1990 opened this issue Aug 10, 2020 · 17 comments
Assignees

Comments

@ravisaini1990
Copy link

I have implemented CustomPlayerNotificationManager and have overridden the actions for locked screen and to show CustomPlayerNotificationManager I have to enable setUseNavigationActions(true) which is showing the previous button in expanded player notification and if I am setting it false notification not visible. Please help locked screen working fine but want to hide 'Previous' icon in expanded view

@andrewlewis
Copy link
Collaborator

@marcbaechinger Please could you take a look? Thanks.

@ravisaini1990
Copy link
Author

So for locked screen i need Rewind, Play/Pause, FastForward
nd for expanded notification view
Rewind, Play/Pause, FastForward along with seekbar

@marcbaechinger
Copy link
Contributor

To hide the navigation button it is sufficient to setUseNavigationactions(false). This makes the previous/next button not appear anymore.

The seekbar is displayed by the system automatically when the duration of the media is set in the playback state of the notification. The PlayerNotificationManager already does this.

I'm not sure what the reason is to subclass the PlayerNotificationManager. For hiding the navigation buttons you don't need to create a custom subclass, just setting the navigation action flag to false is sufficient for this.

I recommend doing this with the PlayerNoticicationManager. Once this works you get some confidence in how this works and you can decide whether you still need to do you own subclass. It works the same way with that if everything is done right.

If you see different results on the lock screen, it can be that the device vendor changed the behaviour on the lock screen. It would be important to know what device you are using and a screen shot from the lockscreen would be helpful as well. Let me know whether that hepls.

@ravisaini1990
Copy link
Author

I am using Mi A3 Android 10. The difference I am getting is that rewind and fast forward options are not coming by default on locked screen that's the reason I wanted to customize it for compact view actions.

Now not using custom actions for compact and have set
playerNotifManager?.setUseNavigationActions(false)
playerNotifManager?.setUseNavigationActionsInCompactView(true)

But on a locked screen, I just get the Play/Pause actions button whereas I need it with rewind and fast forward actions.
@marcbaechinger

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Aug 12, 2020

I'm not sure how the vendor creates the controls on the lock screen. I guess they are doing something differently than normal Android. Vendors can change the lock screen to behave differently.

My guess is that they either just generally allow the play/pause button only. If that is true, then all other audio apps like YouTube Music or Spotify would also only have the play/pause button? Do you see other controls for other audio apps on that device?

If other audio apps have more controls, the vendor probably builds the UI on the lock screen along the action exposed by the media session. I suspect you are using a media session, because normally a media session is required to make the controls on the lock screen appear.

Can you run

adb shell dumpsys media_session

on you device when your app is up and running and paste the output here?

@ravisaini1990

This comment has been minimized.

@ravisaini1990
Copy link
Author

ravisaini1990 commented Aug 12, 2020

Yes i could see the control for other apps, the similar behaviour I need So my player should have following controls -
Locked Screen - 3 action
Rewind, Play/Pause, Fast Forward
For expanded Player in the notification -
Rewind, Play/Pause, Fast Forward along with progress seekbar

Mentioning below the Output of requested command -

> adb shell dumpsys media_session
adb server version (41) doesn't match this client (39); killing...
* daemon started successfully
MEDIA SESSION SERVICE (dumpsys media_session)

2 sessions listeners.
Global priority session is com.android.server.telecom/HeadsetMediaButton (userId=0)
  HeadsetMediaButton com.android.server.telecom/HeadsetMediaButton (userId=0)
    ownerPid=1357, ownerUid=1000, userId=0
    package=com.android.server.telecom
    launchIntent=null
    mediaButtonReceiver=null
    active=false
    flags=65537
    rating type=0
    controllers: 0
    state=null
    audioAttrs=AudioAttributes: usage=USAGE_VOICE_COMMUNICATION content=CONTENT_TYPE_SPEECH flags=0x800 tags= bundle=null
    volumeType=1, controlType=2, max=0, current=0
    metadata: null
    queueTitle=null, size=0
User Records:
Record for full_user=0
  Volume key long-press listener: null
  Volume key long-press listener package: 
  Media key listener: null
  Media key listener package: 
  Callback: null
  Last MediaButtonReceiver: null
  Restored MediaButtonReceiver: null
  Restored MediaButtonReceiverComponentType: 0
  Media button session is com.###.app/###MediaService (userId=0)
  Sessions Stack - have 3 sessions:
    audio_demo com.####.app/audio_demo (userId=0)
      ownerPid=6950, ownerUid=10237, userId=0
      package=com.####.app
      launchIntent=null
      mediaButtonReceiver=null
      active=true
      flags=3
      rating type=0
      controllers: 2
      state=PlaybackState {state=3, position=190459, buffered position=212947, speed=1.0, updated=323847, actions=2360143, custom actions=[], active item id=-1, error=null}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: size=1, description=null, null, null
      queueTitle=null, size=0

    ###MediaService com.###.app/###MediaService (userId=0)
      ownerPid=6950, ownerUid=10237, userId=0
      package=com.####.app
      launchIntent=null
      mediaButtonReceiver=null
      active=false
      flags=3
      rating type=0
      controllers: 0
      state=PlaybackState {state=3, position=341839, buffered position=0, speed=1.0, updated=475345, actions=512, custom actions=[Action:mName='forward, mIcon=2131165653, mExtras=null, Action:mName='backward, mIcon=2131165654, mExtras=null, Action:mName='skip next, mIcon=2131165655, mExtras=null], active item id=-1, error=null}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: null
      queueTitle=null, size=0

    BluetoothMediaBrowserService com.android.bluetooth/BluetoothMediaBrowserService (userId=0)
      ownerPid=17731, ownerUid=1002, userId=0
      package=com.android.bluetooth
      launchIntent=null
      mediaButtonReceiver=null
      active=false
      flags=3
      rating type=0
      controllers: 0
      state=PlaybackState {state=7, position=-1, buffered position=0, speed=1.0, updated=412965, actions=0, custom actions=[], active item id=-1, error=Bluetooth audio disconnected}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: null
      queueTitle=Now Playing, size=0

  Session2Tokens:
Audio playback (lastly played comes first)
  uid=10237 packages=com.####.app 

@ravisaini1990 ravisaini1990 changed the title How to hide the previous /next from expanded notification in exo player Seekbar is not visible in expanded notification of exo player Aug 12, 2020
@marcbaechinger
Copy link
Contributor

marcbaechinger commented Aug 12, 2020

Thanks! I assume the app with the package name you obfuscated is your app.
The output shows that that app exposed two media sessions:

audio_demo com.####.app/audio_demo (userId=0)
      ownerPid=6950, ownerUid=10237, userId=0
...      
###MediaService com.###.app/###MediaService (userId=0)
      ownerPid=6950, ownerUid=10237, userId=0

These two session declare that different actions are supported for each of the session:

audio_demo com.####.app/audio_demo (userId=0
actions=2360143
...
###MediaService com.###.app/###MediaService (userId=0)
actions=512

The first session has the bitmask 2360143 this includes all the actions which you are expecting while not including ACTION_SKIP_PREVIOUS and ACTION_SKIP_NEXT. So I think this is exactly what we want. I'm not sure what the purpose of the second media session is. The action bitmask is 512which is ACTION_PLAY_PAUSE. So I suspect the system somehow got confused or you are not passing the correct session token to the playerNotificationManager.

Can you please make sure that your app:

  1. Creates only one MediaSessionCompat instance:
mediaSession = new MediaSessionCompat(context, MEDIA_SESSION_TAG)
  1. This very instance is passed to the constructor of the MediaSessionConnector:
mediaSessionConnector = new MediaSessionConnector(mediaSession);
  1. The session token of the same instance is passed to playerNotificationManager.setMediaSessiontoken:
playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken());
  1. You call mediaSession.setActive(true)

If you do this and then run adb shell dumpsys media_session again, you should only see one media session in the output. Also, the action bitmask is probably again 2360143 and the session is active. If this works, the system has only one session from your app and should show the lock screen controls accordingly.

@marcbaechinger marcbaechinger changed the title Seekbar is not visible in expanded notification of exo player Previous/Next controls not visible on the lock screen Aug 12, 2020
@ravisaini1990
Copy link
Author

ravisaini1990 commented Aug 12, 2020

Now after the same sequence as you told , here is the output - but still on locked screen i just see play/pause action alone

 adb shell dumpsys media_session
MEDIA SESSION SERVICE (dumpsys media_session)

2 sessions listeners.
Global priority session is com.android.server.telecom/HeadsetMediaButton (userId=0)
  HeadsetMediaButton com.android.server.telecom/HeadsetMediaButton (userId=0)
    ownerPid=1357, ownerUid=1000, userId=0
    package=com.android.server.telecom
    launchIntent=null
    mediaButtonReceiver=null
    active=false
    flags=65537
    rating type=0
    controllers: 0
    state=null
    audioAttrs=AudioAttributes: usage=USAGE_VOICE_COMMUNICATION content=CONTENT_TYPE_SPEECH flags=0x800 tags= bundle=null
    volumeType=1, controlType=2, max=0, current=0
    metadata: null
    queueTitle=null, size=0
User Records:
Record for full_user=0
  Volume key long-press listener: null
  Volume key long-press listener package: 
  Media key listener: null
  Media key listener package: 
  Callback: null
  Last MediaButtonReceiver: null
  Restored MediaButtonReceiver: null
  Restored MediaButtonReceiverComponentType: 0
  Media button session is com.dummy.app/DummmyMediaService (userId=0)
  Sessions Stack - have 5 sessions:
    audio_demo com.dummy.app/audio_demo (userId=0)
      ownerPid=28165, ownerUid=10237, userId=0
      package=com.dummy.app
      launchIntent=null
      mediaButtonReceiver=null
      active=true
      flags=3
      rating type=0
      controllers: 1
      state=PlaybackState {state=0, position=0, buffered position=0, speed=0.0, updated=5884143, actions=2359815, custom actions=[], active item id=-1, error=null}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: size=1, description=null, null, null
      queueTitle=null, size=0

    DummmyMediaService com.dummy.app/DummmyMediaService (userId=0)
      ownerPid=28165, ownerUid=10237, userId=0
      package=com.dummy.app
      launchIntent=null
      mediaButtonReceiver=null
      active=false
      flags=3
      rating type=0
      controllers: 0
      state=PlaybackState {state=3, position=27288, buffered position=0, speed=1.0, updated=5940772, actions=512, custom actions=[Action:mName='forward, mIcon=2131165653, mExtras=null, Action:mName='backward, mIcon=2131165654, mExtras=null, Action:mName='skip next, mIcon=2131165655, mExtras=null], active item id=-1, error=null}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: null
      queueTitle=null, size=0

    BluetoothMediaBrowserService com.android.bluetooth/BluetoothMediaBrowserService (userId=0)
      ownerPid=14903, ownerUid=1002, userId=0
      package=com.android.bluetooth
      launchIntent=null
      mediaButtonReceiver=null
      active=false
      flags=3
      rating type=0
      controllers: 0
      state=PlaybackState {state=7, position=-1, buffered position=0, speed=1.0, updated=5074532, actions=0, custom actions=[], active item id=-1, error=Bluetooth audio disconnected}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: null
      queueTitle=Now Playing, size=0

    audio_demo com.dummy.app/audio_demo (userId=0)
      ownerPid=28165, ownerUid=10237, userId=0
      package=com.dummy.app
      launchIntent=null
      mediaButtonReceiver=null
      active=false
      flags=0
      rating type=0
      controllers: 0
      state=null
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: null
      queueTitle=null, size=0

    audio_demo com.dummy.app/audio_demo (userId=0)
      ownerPid=28165, ownerUid=10237, userId=0
      package=com.dummy.app
      launchIntent=null
      mediaButtonReceiver=null
      active=false
      flags=0
      rating type=0
      controllers: 0
      state=null
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x800 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata: null
      queueTitle=null, size=0

  Session2Tokens:
Audio playback (lastly played comes first)
  uid=10237 packages=com.dummmy.app 

@marcbaechinger
Copy link
Contributor

It seems to me that there are now 4 sessions from your app. Can you confirm? If so it is worth to bring the app in a state that it only exposes one single media session. This way we can rule out problems of the system using another session than we expect.

Can you please send me a screenshot of both, the notification in the notification drawer and the notification on the lock screen?

To clarify what can be expected:

By calling

playerNotificationManager.setUseNavigationActions(false);

the previous/next buttons are hidden in expanded and compact mode.

Calling

playerNotificationManager.setUseNavigationActionsInCompactView(true);

does not change this, as the java doc of setUseNavigationActionsInCompactView says:

/**
   * Sets whether navigation actions should be displayed in compact view.
   *
   * <p>If {@link #useNavigationActions} is set to {@code false} navigation actions are displayed
   * neither in compact nor in full view mode of the notification.
   *
   * @param useNavigationActionsInCompactView Whether the navigation actions should be displayed in
   *     compact view.
   */

On the lock screen you probably see the compact mode that shows only the play/pause button when navigation buttons are disabled. If you expand the notification of the lock screen all three buttons plus the seek bar become visible and can be used by the user from the lock screen without unlocking the device.

Please note that, the PlayerNotificationManager does not support other actions than previous/next to be displayed in compact mode. So in case you are seeing the play/pause button in compact mode, and play/fastForward/rewind in expanded mode, this works as intended. Showing fastForward/rewind in compact mode is currently not supported out of the box.

@marcbaechinger marcbaechinger changed the title Previous/Next controls not visible on the lock screen Rewind/FastForward controls not visible on the lock screen Aug 12, 2020
@ravisaini1990
Copy link
Author

ravisaini1990 commented Aug 12, 2020

https://ibb.co/SrQ2Rp3
In Image above is expanded view and below is the locked screen view in same image

@marcbaechinger

@marcbaechinger
Copy link
Contributor

Ok, that's fine then. If you expand the notification on the lock screen you will have the rewind/fastforward buttons and the seekbar. That's what the PlayerNotificationManager provides. There is no support to make the rewind/fastforward buttons visible in compact mode yet. I mark this issue as an enhancement. It's not something we will start work on it immediately though, so I can't tell you whether and when that will be available.

@marcbaechinger marcbaechinger changed the title Rewind/FastForward controls not visible on the lock screen Provide a way to make fastforward/rewind buttons visible in compact notification mode Aug 12, 2020
@StasKorol
Copy link

@marcbaechinger hi , is there any way to do that? Because I have the same requirement. I need fast forward and rewind buttons in compact notification.

@marcbaechinger
Copy link
Contributor

The PlayerNotificationManager does not offer an API to change the buttons displayed in compact mode at this point.

You can subclass the PlayerNotificationManager and override getActionIndiciesForCompactView(). Please check the javadoc of the method which gives you some details of which you have to take care when overriding.

@StasKorol
Copy link

@marcbaechinger I did so now it works. However expandable mode is now absent (down arrow disapeared)

@StasKorol
Copy link

@marcbaechinger, to be precise. My aim is that there would be rewind and fast-forward buttons in compact mode and expandable mode available.

@marcbaechinger
Copy link
Contributor

If you only override the method getActionIndiciesForCompactView() then you only change the array of actions for the compact view. This does not have an effect on the total actions of the notification. Please review your code and set some breakpoints in the code where you can figure out the the two arrays of actions:

[1] actions in expanded view mode: return value of List<String> getActions(Player player)
[2] actions in compact view mode: return value of getActionIndiciesForCompactView()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants