Recently I've been trying to use CrossSimpleAudioPlayer in Xamarin Forms to play .mp3 file, but I'm receiving this message
System.NullReferenceException: Object reference not set to an instance of an object.
I changed the property Build Action to Embedded Resource, but my error persist, is something i'm missing here?
This is my reference https://blog.xamarin.com/adding-sound-xamarin-forms-app/?utm_medium=social&utm_campaign=blog&utm_source=linkedin&utm_content=simpleaudioplayer-nuget and this is my code:
public void Play() {
var assembly = typeof(App).GetTypeInfo().Assembly;
Stream audioStream = assembly.GetManifestResourceStream("softAlarm." + "softAlarm.mp3");
var audio = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
audio.Load(audioStream);
audio.Play();
}
softAlarm.mp3file located? You need to put in the full path concatenated with dots, prefixed by your project name. So if you file is in a project called SoftAlarm under the resources folder, you should state:GetManifestResourceStream("SoftAlarm.Resources.softAlarm.mp3")- Gerald VersluisGetManifestResourceStream("softAlarm.mp3")as the OS will find it for you. But not entirely sure on this one. The link you're referring to also places the audio file in the shared library. That way you don't need any duplicate files as well :) - Gerald Versluis