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

Playback Resumption with external applications #1064

Open
PaulWoitaschek opened this issue Feb 4, 2024 · 2 comments
Open

Playback Resumption with external applications #1064

PaulWoitaschek opened this issue Feb 4, 2024 · 2 comments
Assignees
Labels

Comments

@PaulWoitaschek
Copy link
Contributor

On my audiobook player I received this PR which would cause all onConnect commands which do not come from my package to prepare the last played book.

PaulWoitaschek/Voice#2280

Previously it was already a little hacky because onGetSessionwas invoking the isReleased using reflection, see #422

I wonder if the proposed PR is really the intended solution with media3 to support playback resumption coming from external applications.
Could you give some guideance (and even better: Write some documentation) how this is designed to work?

@ASGusev
Copy link

ASGusev commented Feb 4, 2024

I created the PR mentioned above. I tried to use the SimpleWear's media controller with Voice: I connected to Voice from the SimpleWear and hit the play button expecting Voice to continue playing the last played media like most other apps do, but it didn't. So, I looked at Voice's code and saw the onConnect loading the playback position if the connecting controller has Android Auto's package id. I relaxed the package id check to load position for all package ids but Voice's own. Then, the playback would resume from the last position on SimpleWear's play button but if the app was swiped away from the app drawer after being started by SimpleWear, it could end up in a state when the process was alive but the session was already released which meant that the app wasn't able to run playback even from it's main UI until being forcefully stopped, so I made onGetSession create a new session if the old one has been released

@marcbaechinger marcbaechinger self-assigned this Feb 5, 2024
@marcbaechinger
Copy link
Contributor

An external controller can connect to the session and then use the setMediaItems method to set items to the player and then call play. The app owning the controller must be in the foregropund for that to work on all API levels.

If the controller calls play when the playlist is empty, then I'd expect that onPlaybackResumption is called to fill the playlist with what is returned from the callback. That works with the demo app. Can you check why that doesn't work for your app? You can basically put a break point into handleMediaControllerPlayRequest to see what happens there.

That's the intended API Media3 offers. For a controller this would just be to build the controller and then call play:

controller.play()

I have verified this with the demo app:

  1. Uncomment these lines in PlaybableForderActivivty
  2. Add the lines
if (controller.mediaItemCount == 0) {
  controller.play()
}

at the end of PlayerActivity.setController.

With the above changes in the demo app, the PlayerActivity calls play on an empty controller which triggers playback resumption.

The mentioned PR does changes in the app logic that aren't specific to Media3 APIs, so the best person to review that change is the app developer I think.

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

No branches or pull requests

3 participants