In this recipe, we will learn how to play both simple audio files and songs stored on the device.
Create a new Single View Application in Xamarin Studio and name it PlayMusicApp
.
Perform the following steps:
Add three buttons to the view of the controller.
Add the following
using
directive in thePlayMusicAppViewController.cs
file:using MonoTouch.MediaPlayer;
Add the following two fields in the class:
private MPMusicPlayerController musicPlayer; private MPMediaPickerController mediaPicker;
Add the following code in the
ViewDidLoad
method:this.mediaPicker = new MPMediaPickerController(MPMediaType.Music); this.mediaPicker.ItemsPicked += MediaPicker_ItemsPicked; this.mediaPicker.DidCancel += MediaPicker_DidCancel; this.musicPlayer = MPMusicPlayerController.ApplicationMusicPlayer; this.btnSelect.TouchUpInside += async (s...