电影项目的 UIImagePickerController
我正在 iPhone 3GS 上编写一个简单的视频上传应用程序,首先将用户引导至相册,然后选择要共享或上传的视频。我按以下方式使用 UIImagePickerController:
videoPickerCtrl = [[UIImagePickerController alloc] init];
videoPickerCtrl.delegate = self;
videoPickerCtrl.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoPickerCtrl.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoPickerCtrl.sourceType];
videoPickerCtrl.allowsImageEditing = NO;
videoPickerCtrl.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
[window addSubview:videoPickerCtrl.view];
但我可以看到,一旦调用控制器,就会出现一个令人不安的视频修剪界面。一旦我按下“选择”,无论我是否触摸修剪控件,视频都会被修剪。有没有办法绕过这个修剪界面并直接获取视频文件的路径?
I am writing a simple video uploader application on iPhone 3GS where I first direct the user to photos album, and then select the video to share or upload. I am using the UIImagePickerController in the following way:
videoPickerCtrl = [[UIImagePickerController alloc] init];
videoPickerCtrl.delegate = self;
videoPickerCtrl.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoPickerCtrl.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoPickerCtrl.sourceType];
videoPickerCtrl.allowsImageEditing = NO;
videoPickerCtrl.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
[window addSubview:videoPickerCtrl.view];
But I can see that once the controller is invoked, there is a disturbing video trimming interface that is presented. Once I press "choose", the video is always trimmed no matter whether I touch the trimming controls or not. Is there any way to get around this trimming interface and directly get the path of the video file ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该设置
allowsEditing = NO;
而不是allowsImageEditing = NO;
(它已在 3.1 中弃用)。然后,除非选择的电影长度超过 10 分钟,否则不应出现修剪界面(来自文档:“最大电影时长为 10 分钟。如果用户选择的电影时长超过 10 分钟,他们将被迫修剪保存之前先执行此操作。”)。You should set
allowsEditing = NO;
instead ofallowsImageEditing = NO;
(which has been deprecated in 3.1). Then, the trimming interface should not appear unless the selected movie is longer than 10 minutes (from the docs: "Maximum movie duration is 10 minutes. If a user picks a movie that is longer in duration than 10 minutes, they are forced to trim it before saving it.").有趣的问题。这仅供其他人查看时参考。在 iPad OS 3.2 上,我在检索视频时发现了一些问题,尽管选择器可以工作,而且我可以从相册中选择视频,而不仅仅是从相机胶卷中选择视频。
这是我的工作代码片段
调用
这是委托方法
但是我从选择器检索的视频 URL 具有以下形式
所以在我看来,视频可能是通过修剪代码进行处理的即使我选择整个视频。另请注意,当我通过 iTunes 加载该影片时,其最初类型为 m4v,其类型为 MOV,这当然无法在设备上播放!我确实尝试播放该 URL,但收到一条警告说“这种电影无法播放”
我不太明白 Apple 在这里播放什么,该 API 似乎不能真正用作加载和播放的方式播放照片库中的视频。
希望 iOS 4 能够更早地推出,但对于我的 iPad 应用程序来说,这还需要几个月的时间。
Interesting problem. This is just for information should anyone else be looking at this. On iPad OS 3.2 I have found some problems retrieving video, although the picker works and I can select video from albums and not just from the camera roll.
Here's my working code frag
The call
And here is the delegate method
However the video URL which I retrieve from the picker has the form
So it looks to me that the Video might be being processed through the trimming code even if I'm selecting the video as a whole. Note also that the movie, originally of type m4v when I loaded it through iTunes is of type MOV, which is of course unplayable on the device! I did try playing the URL but I received an alert saying "This kind of movie can't be played"
I don't quite understand what Apple is playing at here, the API appears not to really be usable as a way of loading and playing video from the photo library.
Hopefully IOS 4 will be more forthcoming, but for my iPad app, that's still months away.
好吧,在仔细查看 SDK 文档后,我很久以前就让它工作了。我可以从 3GS 上的相机胶卷目录中获取视频。但我找不到 UIImagePickerController 可以从相机胶卷以外的目录中选择视频的任何方法(例如,用户通过 iTunes 同步视频的设备照片库)。 SDK中有没有标准的方法可以做到这一点?
Ok so I got it working long back after carefully looking at SDK docs. I am able to get videos from Camera Roll directory on my 3GS. But I can not find any way in which UIImagePickerController can choose video from directories other than Camera Roll(for instance, device's Photo Library where the user syncs videos through iTunes). Is there any standard way in SDK to do that ?