Baseflow / XamarinMediaManager

Cross platform Xamarin plugin to play and control Audio and Video
https://baseflow.com
MIT License
768 stars 305 forks source link

Add flag immutable for intent #849

Closed valentin-debris closed 2 years ago

valentin-debris commented 2 years ago

:sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

This is a bug fix for make the plugin compatible with Android 12. It requires now FLAG_IMMUTABLE (or MUTABLE) for every PendingIntent.GetActivity(), otherwise, it fails to load the app.

:arrow_heading_down: What is the current behavior?

The app crashes as soon as it starts, with the error "Caused by: java.lang.IllegalArgumentException: fr.magina.radioperfecto: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles."

:new: What is the new behavior (if this is a feature change)?

No more crash !

:boom: Does this PR introduce a breaking change?

No, it's backward compatible

:bug: Recommendations for testing

:memo: Links to relevant issues/docs

845

:thinking: Checklist before submitting

ghost commented 2 years ago

Hi @martijn00 ! Any plans on when this will be in a nuget update?

floriantanneur commented 2 years ago

Hello @martijn00, Any news on this update ? Thanks.

hberrio commented 2 years ago

Hi @martijn00, Any news on this update?

abreucruz commented 1 year ago

hi @martijn00 do you have any updated package? for API 31+ with Samsung it's not working anymore in order to play an audio I have to use API 30 as a target but Google is only accepting API 31+ so my App it's not playing any Audios on Samsung devices.

okains commented 1 year ago

there is a patch / hack that will get this working in 12+, just explicitly set the speed to 1 before playing the audio, that will get you past this issue for now. This is documented in another ticket, can't find the reference but that's the gist of it.

float speed = 1;

CrossMediaManager.Current.Speed = speed;

await CrossMediaManager.Current.Play(AudioTrackUrl);

abreucruz commented 1 year ago

hi @okains I just did what you mentioned and I'm getting this error: MediaSession cannot be null. Make sure the MediaBrowserService sets it up Parameter name: MediaSession

Note: I changed Target Android version to API 31(New requirement from Google). Apparently the component failed to Init but I'm not getting any error during init process.

okains commented 1 year ago

@abreucruz

Make sure that you have called init on the MediaSession instance in App: CrossMediaManager.Current.Init();

abreucruz commented 1 year ago

@okains Yes thanks I did, my code works fine on API 30 but as soon I change it to API 31 the Play method does not works.

abreucruz commented 1 year ago

Hello @okains any other ideas? I'm struggling with this issue since a week ago and the only issue is that google now require API 31+ for new App updates and with this version the Nuget Package does not work properly