- Home /
U3DXT - Choose Video from Photos App
Hi,
I am new to use this plugin, may I ask if it is possible to:
Choose a existing video from Photos App using its native UI?
If so, is it OK to give me some sample code for me to follow? Or where can I start?
In additional to this, is it possible to be able to play the chosen video on a plane or on a cube?
Thank you. Derek
Answer by u3dxt · Jul 01, 2014 at 05:54 PM
Hi, to get videos from the native UI, you can use the following. BTW, this is copied from our high-level API: https://github.com/vitapoly/u3dxt/blob/master/src/highlevel/core/GUI/GUIXT.cs, except added one line to specify "public.movie" as the media type. There is a TODO in _OnPickedMedia() for you to do something with the URL of the movie file. However, our plugin does not allow you to import that into a texture.
private static UIImagePickerController _picker;
private static UIPopoverController _popover;
public static void ShowImagePicker(UIImagePickerControllerSourceType source = UIImagePickerControllerSourceType.PhotoLibrary,
UIImagePickerControllerCameraDevice cameraDevice = UIImagePickerControllerCameraDevice.Rear) {
_picker = new UIImagePickerController();
_picker.mediaTypes = new Object[] { "public.movie" }; // pick only movies
_picker.sourceType = source;
_picker.DidFinishPickingMediaWithInfo += _OnPickedMedia;
_picker.DidCancel += _OnCancelledPick;
if (source == UIImagePickerControllerSourceType.Camera)
_picker.cameraDevice = cameraDevice;
var rootVc = UIApplication.deviceRootViewController;
if (CoreXT.IsiPad && (source != UIImagePickerControllerSourceType.Camera)) {
if (_popover == null) {
_popover = new UIPopoverController(_picker);
_popover.DidDismiss += _OnCancelledPick;
_popover.shouldDismissHandler = _ShouldDismissPopover;
} else {
_popover.contentViewController = _picker;
}
var rect = rootVc.view.bounds;
rect.x = rect.width / 2;
rect.y = rect.height;
rect.width = 1;
rect.height = 1;
_popover.PresentPopover(
rect,
rootVc.view,
UIPopoverArrowDirection.Down,
true);
} else {
rootVc.PresentViewController(_picker, true, null);
}
}
private static void _OnPickedMedia(object sender, UIImagePickerController.DidFinishPickingMediaWithInfoEventArgs e) {
if (_popover != null)
_popover.DismissPopover(true);
else if (_picker.parentViewController != null)
_picker.parentViewController.DismissViewController(true, null);
else
UIApplication.deviceRootViewController.DismissViewController(true, null);
_picker = null;
_popover = null;
NSURL url = null;
if (e.info.ContainsKey(UIImagePickerController.ReferenceURL))
url = e.info[UIImagePickerController.ReferenceURL] as NSURL;
//TODO: do something with the URL
}
private static void _OnCancelledPick(object sender, EventArgs e) {
if (_popover != null) {
// _popover.DismissPopover(true);
} else if (_picker.parentViewController != null) {
_picker.parentViewController.DismissViewController(true, null);
} else {
UIApplication.deviceRootViewController.DismissViewController(true, null);
}
_picker = null;
_popover = null;
}
private static bool _ShouldDismissPopover(UIPopoverController popover) {
return true;
}
Hello,
Thank you for your answer. I have tried your code and it works. But I have more question regarding this.
The url is a reference url of the video, is it possible to know its actual location, its path?
I tried to use the url directly by putting: PlayStrea$$anonymous$$gFullscreen$$anonymous$$ovie(url.tostring(), true, U3DXT.iOS.Native.$$anonymous$$ediaPlayer.$$anonymous$$P$$anonymous$$ovieControlStyle.Default) But it doesn't play the video. What have I done wrong in here?
Your answer
![](https://koobas.hobune.stream/wayback/20220613152845im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
U3DXT Init failed, everything is setup 1 Answer
Using MediaExporter to save to MP3 1 Answer
U3DXT IAP - prevent pending transactions from starting download after Init() 1 Answer
u3dxt causing failed validation 2 Answers
Has U3DXT been abandoned? 2 Answers