-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix android auto resume on reconnect issues #7156
Conversation
Automatically restarting playback should be handled by Android Auto.
Previously the MediaSession object created in PlaybackService in onCreate would be completely empty. This seemed to confuse Android Auto, and prevented it from restarting playback. Filling the MediaSession object using the data from the player state at onCreate resolves this problem. This is documented in Android Auto docs[1], albeit indirectly and somewhat confusingly. Also move the setSessionToken call to the end of onCreate handler to ensure that the media session has already been completely filled by the time the session token is made available to the framework. There is no evidence that this is required; however intuitively, this is likely the trigger for the framework to start querying the media session. The change was tested both with Desktop Head Unit and with a real vehicle. [1] https://developer.android.com/training/cars/media/#initial-playback-state
Thanks for your changes related to the playback service. I'm not sure how much time we should spend on tweaking the existing service. In the near future, we should upgrade to media3 (see also #6608), which might require considerable changes to the playback service. Maybe some of these changes would then deprecate changes you are doing now. Would you maybe be interested in working on #6608? |
I see your point. Upgrading to a currently supported version of the framework before trying to fix issues like this and (#6576) makes sense to me. However, in #6608 you said:
Do I understand correctly, that your opinion has changed, and you would now prefer to update the library first? At the same time, this specific issue has received a lot of user feedback (see forums and Play Store reviews), especially in the light of Google Podcasts dumping all of its users. I think it would be better for the project to include this fix. The amount of code changed is very small, and my intuition says the change should be relatively safe (however, of course, I'm very new to the codebase, so there may be unintended consequences). Regarding #6608, let's continue the discussion there. |
I still think upgrading to media3 won't fix all the problems with media resumption but I think we need to upgrade at some point anyway.
I also feel like it should be quite safe and am not against merging it. Will do some testing. Because you opened a bunch of playback service PRs, my idea with the message was just to avoid spending too much time ironing out bugs with the old service when we need to upgrade anyway eventually. |
Understood, thanks, all makes sense. |
Thanks! Will be released in 3.5.x |
Thanks @hades |
Previously this was accomplished by manually subscribing to the Android Auto state. This was prone to failure, since it would only work as long as the service is running.
The correct way of handling this according to Android Auto docs[1] is to provide a valid PlaybackState when the service is bound. We accomplish this here by filling out the media session object whenever the media player is recreated.
Fixes #6698
[1] https://developer.android.com/training/cars/media/#initial-playback-state
Checklist
./gradlew checkstyle spotbugsPlayDebug spotbugsDebug :app:lintPlayDebug