ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
782 stars 458 forks source link

Update Android implementation to use media3 #942

Open ryanheise opened 2 years ago

ryanheise commented 2 years ago

Feature proposal

Update the android implementation to use media3, documented here:

https://developer.android.com/guide/topics/media/media3 https://github.com/androidx/media

Although this is still in alpha/beta so wait until it's stable.

This is quite a departure from the old API with the introduction of a Player interface (although I preferred the old API since it was easier to unify with the iOS API). Ideally, try to implement an abstraction over the new API that makes it more closely resemble the old API.

Motivating use case(s)

To provide access to the latest Android media features, and take advantage of the new asynchronous API.

bypass112 commented 10 months ago

Hello, from what I've seen Android side is using Exoplayer2, but from the latest release it seems that the project is now deprecated and suggest migration to androidx.media3. Will this affect the audio_service package on the long run? Also there seems to be a migration script available, but I'm not sure if this is compatible with your solution. Thank you!

ryanheise commented 10 months ago

Yes, I was just thinking about the ExoPlayer migration recently, although note that it's not audio_service that uses ExoPlayer but just_audio. At the moment, my approach is to pin the ExoPlayer version to the same version that video_player is also using so that developers are unlikely to run into conflicts. When video_player makes the transition, just_audio will also make the transition. Actually, since this migration would no longer use the ExoPlayer dependency, I wouldn't expect any versioning conflict when that happens, and so we would not even be required to do the migration at exactly the same time.

I consider audio_service's dependency on media3 to be a separate issue though (it's not related to ExoPlayer), and I think we can tackle it at a later time independently of any migration of ExoPlayer in just_audio. Personally I find the media3 API to be a bit inconvenient to use from Java, and I may need to convert it all into Kotlin before I consider looking at media3. Also, the media3 API is radically different and would introduce a breaking change that I'm happy to put off for the time being.

bypass112 commented 10 months ago

Thank you for the update and the info! My bad about mixing audio_service and just_audio. Untill the project is migrated to media3, should def exoplayer_version = "2.18.7" be redefined to 2.19.1? As it seems that there are a few major bugs and improvements addressed in this version and it may make the Flutter project overall more stable? I'm not sure what is the best practices about your projects, that's why I am asking about the Exoplayer version upgrade. Note: video_player seems to still be using [2.18.7].(https://github.com/flutter/packages/blob/3b602e77e69aac91dbbf2e18260fb70d3a42df23/packages/video_player/video_player_android/android/build.gradle#L51C35-L51C35)

ryanheise commented 10 months ago

I've intentionally pinned exoplayer to the same version that video_player uses and try to upgrade the version in sync with what video_player does. I did used to upgrade the version independently of video_player although I was receiving reports from developers running into compatibility issues when they tried to use both just_audio and video_player in the same app, unless the versions of exoplayer matched exactly. This just makes it simpler to avoid that issue.