adrianstevens / Xamarin-Plugins

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

SimpleAudioPlayer: object reference error on iOS after playback complete #96

Open KnoxCameron opened 2 years ago

KnoxCameron commented 2 years ago

I have an app that I wrote and released for Android and am now testing and modifying as required for iOS. I use SimpleAudioPlayer as an easy cross-platform way of playing audio clips.

I only ever need to play one clip at a time, so I wrote the program to instantiate the object and reference the "current" player, similar to:

player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;

I intercept the playback ended event and tell it the next clip to play. This worked fine on Android. On iOS, it threw an error that the object had been modified or no longer existed (sorry I don't have the exact error but can re-created it if necessary). I ended up working around the issue by using the the create player call like this instead:

player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.CreateSimpleAudioPlayer();

And calling this again in each playback ended event to re-create the object, as well as adding the playback ended event again.

Is this difference in behaviour between Android and iOS expected? The code as modified for iOS does also work on Android, but I don't know if there might be side effects?