hi friends I'm trying to play an mp3 for the notifications of an App that I developed in Xamarin.Forms I was reading about it and very similar to SQLite I must handle this event with an interface, but I have trouble referencing it
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
I think maybe it's the way I try to reproduce it,
I try to execute my method of playing from this class
public class AudioService
{
//private IAudio awx;
public void Play() {
DependencyService.Get<IAudio>().PlayAudioFile("beep.mp3");
}
}
// Interfáz
public interface IAudio
{
void PlayAudioFile(string fileName);
}
This is my handler class Android , I put my beep file in the Assets
folder
public class AudioService: IAudio {
public AudioService() {}
public void PlayAudioFile(string fileName) {
var player = new MediaPlayer();
var fd = global::Android.App.Application.Context.Assets.OpenFd(fileName);
player.Prepared += (s, e) => {
player.Start();
};
player.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length);
player.Prepare();
}
}
Does anyone know anything about it?