Skip to content

Register correct MediaButtonReceiver in MediaSessionLegacyStub #314

Closed

Description

@marcbaechinger

Media3 Version

Media3 1.0.0

Devices that reproduce the issue

All devices

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

  1. Start session demo app
  2. Start playback.
  3. Pause playback
  4. Dismiss app from recent app.
  5. Press play on a BT headset

Expected result

App is started again

Actual result

CancellationException because the PendingIntent is cancelled.

Media

Any media from the session demo

Bug Report

Activity

  1. marcbaechinger commented on Apr 11, 2023

    @marcbaechinger
    ContributorAuthor

    When running

    adb shell dumbsys media_session
    

    The following pending intent is registered:

    Last MediaButtonReceiver: MBR {pi=PendingIntent{c9283b3: PendingIntentRecord{df4cd70 com.example.android.uamp.next startForegroundService}}, type=3
    

    However, the pending intent is already cancelled by the the MediaSessionImpl when the session is released. This is wrong, instead the pending intent needs to be removed entierly.

    instead, the MediaSessionLegacyStub should do:

    When the session is created:

    1. Check whether the app has a broadcast receiver for ACTION_MEDIA_BUTTON in the manifest. If this is the case this receiver should be used as the component and pending intent passed to the constructor of MediaSessionCompat.
    2. If no app provider receiver is provided and the session is housed by a service, the pending intent is used as the mbr component and pending intent.
    3. If not in a service, a new runtime broadcast receiver is used instead.

    When the session is released:

    1. Use mediaSessionCompat.setMediaButtonReceiver(null) unless the app has provided its own broadcast receiver in the manifest.

    Note: An app can only be restarted by BT headset if:

    1. A broadcast receiver for ACTION_MEDIA_BUTTON is registered in the manifest by the app developer. With this the app claims to be able to start playback when the service is started with a pending intent from BT headset.
    2. The apps needs to implement playback resumption like described in MediaLibraryService throws ForegroundServiceDidNotStartInTimeException #167 (comment)

    A fix for this is in review internally.

    Related documentation:
    https://developer.android.com/guide/topics/media-apps/mediabuttons

  2. marcbaechinger commented on Apr 21, 2023

    @marcbaechinger
    ContributorAuthor

    Closing as this is released with 1.0.1.

  3. locked and limited conversation to collaborators on Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions