adrianstevens / Xamarin-Plugins

Cross-platform Plugins for Xamarin, Xamarin.Forms and Windows
https://www.nuget.org/packages/Xam.Plugin.SimpleAudioPlayer/
MIT License
132 stars 53 forks source link

Fails on android after a few calls #92

Open ajmilford opened 2 years ago

ajmilford commented 2 years ago

In my shared code I have: called in the constructor of a view (actually a Rg.Plugins.Popup.Pages.PopupPage view): Stream beepStream = UIBits.ImageFactory.Instance.GetAsset("UIBits.Assets.beep.mp3"); audioPlayer = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer(); audioPlayer.Load(beepStream); then later in response to an action: audioPlayer.Play();

this initially works fine. But after maybe a dozen times (I haven't actually counted) the sound stops being produced. In the application output I see:

[MediaPlayer-JNI] start [MediaPlayerNative] start [MediaPlayerNative] message received msg=300, ext1=0, ext2=0 [MediaPlayerNative] Received SEC_MM_PLAYER_CONTEXT_AWARE [MediaPlayerNative] callback application [MediaPlayerNative] back from callback [MediaPlayerNative] message received msg=100, ext1=1, ext2=-19 [MediaPlayerNative] error (1, -19) [MediaPlayerNative] callback application [MediaPlayerNative] back from callback [MediaPlayer] Error (1,-19)

do I need to do something else when the sound is played to release resources or something? or is this a bug?

adrianstevens commented 2 years ago

Can you provide more details? What device are you using? What version of Android? And how frequently are you playing the sound?

ajmilford commented 2 years ago

I fixed the issue by making 'audioPlayer' a static and modifying the constructor to:

if (audioPlayer != null) return; Stream beepStream = UIBits.ImageFactory.Instance.GetAsset("UIBits.Assets.beep.mp3"); audioPlayer = CrossSimpleAudioPlayer.CreateSimpleAudioPlayer(); audioPlayer.Load(beepStream);

So 'audioPlayer' is only created once.

It is running on a Samsung Galaxy S7 Edge. Not called particularly frequently - minimum time between calls would be 10s. Android V8.0.0.