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

Fix android auto resume on reconnect issues #7156

Merged
merged 2 commits into from May 18, 2024

Conversation

hades
Copy link
Contributor

@hades hades commented May 1, 2024

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

hades added 2 commits May 1, 2024 13:00
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
@ByteHamster
Copy link
Member

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?

@hades
Copy link
Contributor Author

hades commented May 1, 2024

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:

So I'm pretty sure that upgrading to media3 will not directly solve any of the issues we currently have, but will cause us a bunch of new issues. So this rewrite is quite low on my list currently.

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.

@ByteHamster
Copy link
Member

So I'm pretty sure that upgrading to media3 will not directly solve any of the issues we currently have, but will cause us a bunch of new issues. So this rewrite is quite low on my list currently.

Do I understand correctly, that your opinion has changed, and you would now prefer to update the library first?

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 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).

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.

@hades
Copy link
Contributor Author

hades commented May 8, 2024

Understood, thanks, all makes sense.

@ByteHamster ByteHamster changed the title fix andoird auto resume on reconnect issues Fix android auto resume on reconnect issues May 18, 2024
@ByteHamster ByteHamster merged commit 84b6f44 into AntennaPod:develop May 18, 2024
6 checks passed
@ByteHamster
Copy link
Member

Thanks! Will be released in 3.5.x

@tonytamsf
Copy link
Member

Thanks @hades

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

Successfully merging this pull request may close these issues.

Inconsistent autoplay behavior when connected to Android Auto
3 participants