I'm trying to play an .wav audio file, for which I followed this answer.
I followed this answer but I get an error message on audio.Load(stream);
says System.NullReferenceException: Object reference not set to an instance of an object
.
To me it seems that the problem is that, audio.load()
couldn't find the audio file, which is in Resource/raw
path.
Complete Code
private void Counter(object sender, EventArgs e)
{
timer_countdown = new Timer();
timer_countdown.Interval = 1000;
timer_countdown.Elapsed += OnTimedEventIDCamera;
timer_countdown.Enabled = true;
timer_countdown.AutoReset = true;
timer_countdown.Start();
}
private void OnTimedEventIDCamera(object source, ElapsedEventArgs e)
{
Seconds++;
if (Seconds == 3)
{
var stream = GetStreamFromFile("beepSound.wav");
var audio = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
audio.Load(stream);
audio.Play();
}
}
Stream GetStreamFromFile(string filename)
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("yourprojectname." + filename);
return stream;
}
stream
is null?resources/raw
directory as told in the answer linked above