MPMediaPickerController Usage

I have been unable to correctly get the Music Selection to show up. What I ultimately want to do, is to be able to pick a number of songs, and then return the selected song data to use like a playlist.

I was unable to get the following code to work:

public MPMediaPickerController Picker

void OnClick()
Picker = new MPMediaPickerController();
Picker.allowsPickingMultipleItems = true;

The problem comes from the PresentViewController, and Objective-C examples show a difference when using “self” to present the view controller. I tried using “this.Picker” but was unnable to get it to work. The crash when OnClick() is fired is something along the lines of “Tried to present modal view on itself”.

I also read that another problem is calling the picker over unity, and it simply not showing up; this might have also been the case as I tried Picker.PresentViewController(Picker.presentedViewController,true,null) and Xcode had some log text show up, but nothing happened on the phone.

If anyone knows how to fix it (and also how to use the MPMediaPickerControllerDelegate class to return the picked songs) that would be amazing.



Tell the rootViewController to present the MPMediaPickerController. A few minor releases ago, we auto wrapped event handling so you don’t need to create Delegate classes anymore. Check out this code block for an example:

using UnityEngine;
using System.Collections;
using U3DXT.iOS.Native.MediaPlayer;
using U3DXT.iOS.Native.UIKit;

public class MediaPicker : MonoBehaviour {

	void OnGUI()
		if ( GUI.Button(new Rect(100,100,300,400), "Pick Songs") ){

	void PickSongs()
		MPMediaPickerController mediaPicker = new MPMediaPickerController();
		mediaPicker.allowsPickingMultipleItems = true;
		mediaPicker.DidPickMediaItems += HandleDidPickMediaItems;
		// add it to the root view controller
		UIApplication.deviceRootViewController.PresentViewController(mediaPicker, true, null);

	void HandleDidPickMediaItems (object sender, MPMediaPickerController.DidPickMediaItemsEventArgs e)
		(sender as MPMediaPickerController).DismissViewController(true, null);

		Debug.Log (e.mediaItemCollection.count);

Hi can we continue this post please… How retrieve an array with e.mediaItemCollection. for have an Audioclip array and can Play the files in Unity ?

thanks ,