It’s not that difficult but there’s not an awful lot about it. I haven’t tried it with .MP3 files but what I’ve done works with .wav.

First create a project folder containing the sound files. Each file should be set to Content in the property/build Action.


Then define AvAudioPlayer to play the file. I created three in the class:

public static AVAudioPlayer [] player = new AVAudioPlayer[3];
private static int playIndex {get;set;}
       public static void PlaySound(string filename)
            if (playIndex == 3)
                playIndex = 0;
            if (player[playIndex] != null)
                var file = Path.Combine("sounds", filename);
                var Soundurl = NSUrl.FromFilename(file);
                player[playIndex] = AVAudioPlayer.FromUrl(Soundurl);
                var onePlay = player[playIndex];
                onePlay.CurrentTime = onePlay.Duration*2;
                onePlay.NumberOfLoops = 1;
                onePlay.Volume = 1.0f;
                onePlay.FinishedPlaying += DidFinishPlaying;
            catch (Exception e)
                LogLine("PlaySound: Error: " + e.Message, true);

        public static void DidFinishPlaying(object sender , AVStatusEventArgs e)
            if (e.Status)
                // your code


The playIndex int variable tracks which is the next AvAudioPlayer to be used. Note that the file must specify the directory used – my files are in sounds. The player[] variables exist at the class level not locally because you don’t want the garbage collector to zap them once it exits the PlaySound method.

The AVAudioPlayer.FinishedPlaying event handler (delegate in Apple’s terms) lets you catch when it finishes playing. The AvStatusEventArgs.Status is a bool indicating if it has finished.

Because in my App, two possibly three sounds could play simultaneously, I used three AvAudioPlayers. Without them, you have to stop the current sound playing.

Leave a Reply

Post Navigation