I try to play a short sound when a user clicks on a specific button. But the problem is that I always get a reference to an object that is not set to an instance object . mean null!
First I tried MonoTouch.AudioToolBox.SystemSound.
MonoTouch.AudioToolbox.AudioSession.Initialize(); MonoTouch.AudioToolbox.AudioSession.Category = MonoTouch.AudioToolbox.AudioSessionCategory.MediaPlayback; MonoTouch.AudioToolbox.AudioSession.SetActive(true); var t = MonoTouch.AudioToolbox.SystemSound.FromFile("click.mp3"); t.PlaySystemSound();
Let me notice that "click.mp3" is in my folder with the root solution, and it is marked as Content. Another approach is MonoTouch.AVFoundation.AVAudioPlayer .
var url = NSUrl.FromFilename("click.mp3"); AVAudioPlayer player = AVAudioPlayer.FromUrl(url); player.FinishedPlaying += (sender, e) => { player.Dispose(); }; player.Play();
But the same mistake. I was looking for him, and I see that many people have this problem. We need to know if this is a mistake or not.
source share