Implementing the iOS SoundHandler using the AVAudioPlayer framework

The AVAudioPlayer class is the framework we will be using to play and control our audio streams in iOS, so let's begin by adding a new folder called Sound to the iOS project. We then want to create a new file called SoundHandler.cs that will inherit the ISoundHandler interface:

public class SoundHandler : ISoundHandler 
    { 
         
    } 

Now let's create a private AVAudioPlayer object and add our public IsPlaying, which will hold the playing status of the audio player:

private AVAudioPlayer _audioPlayer; 
 
public bool IsPlaying { get; set; } 

Then we add in the functions of the interface. In each function, we will be using the audio player object to do all our audio processing:

public void Load() ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.