Xamarin-Plugins
Xamarin-Plugins copied to clipboard
Fails on android after a few calls
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?
Can you provide more details? What device are you using? What version of Android? And how frequently are you playing the sound?
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.