Playing Sound with AVAudioPlayer

PDF for offline use:
Related SDKs:

Let us know how you feel about this.


0/250
Thanks for the feedback!

last updated: 2016-10

This article shows how to use a helper class to control the playback of sound using an AVAudioPlayer.

About the AVAudioPlayer

The AVAudioPlayer is used to playback audio data from either memory or a file. Apple recommends using this class to play audio in your app unless you are doing network streaming or require low latency audio I/O.

You can use the AVAudioPlayer to do the following:

  • Play sounds of any duration with optional looping.
  • Play multiple sounds at the same time with optional synchronization.
  • Control volume, playback rate and stereo positioning for each sounds playing.
  • Support features such as fast forward or rewind.
  • Obtain playback level metering data.

AVAudioPlayer supports sounds in any audio format provided by iOS, tvOS and OS X such as .aif, .wav or .mp3.

Playing Sounds in macOS

Because macOS supports the same Audio Toolbox classes as iOS, please see our iOS Playing Sound with AVAudioPlayer documentation for the full details of playing audio in a Xamarin.Mac app.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.