- Home /
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;
Picker.PresentViewController(Picker,true,null)
}
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.
Thanks,
Blueteak
Answer by u3dxt · Jan 16, 2014 at 07:21 PM
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") ){
PickSongs();
}
}
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);
}
}
BTW, if you are only interested in specific types, video, music video, songs, etc. You can specify the $$anonymous$$P$$anonymous$$ediaTypes when creating the $$anonymous$$P$$anonymous$$ediaPickerController.
Answer by eclyptik · Jun 09, 2014 at 11:01 PM
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 ,
Eclyptik
Your answer
Follow this Question
Related Questions
Can I use Unity network system with Multipeer connectivity ? 0 Answers
Application crashes 2 Answers
Launching the appstore via u3dxt 1 Answer
How to get local currency u3dxt 1 Answer