MPMoviePlayerController 不播放从 UIImagePickerController 选取的电影
我有奇怪的 MPMoviePlayerController 行为。它不想播放刚刚从 UIImagePickerController 的相机胶卷中选择的电影。但是当我使用 UIImagePickerController 捕获电影时 - 有时它在 MPMoviePlayerController 中播放得很好。
这是 UIImagePickerController 初始化:
mediaPickerController = [[[UIImagePickerController alloc] init] autorelease];
NSArray *types = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
mediaPickerController.sourceType = sourceType;
mediaPickerController.mediaTypes = types;
mediaPickerController.videoQuality = qualityType;
mediaPickerController.delegate = self;
[self presentModalViewController:mediaPickerController animated:YES];
这是 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 委托方法:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *fileURL = [info objectForKey:UIImagePickerControllerMediaURL];
playerView = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[playerView.view setFrame:mediaPreview.bounds];
[playerView setScalingMode:MPMovieScalingModeAspectFit];
[playerView setControlStyle:MPMovieControlStyleEmbedded];
[playerView setShouldAutoplay:NO];
[playerView prepareToPlay];
[mediaPreview addSubview:playerView.view];
}
另一个奇怪的问题 - 当我使用 UIImagePickerController 的 sourceType = Camera 时,然后委托返回下一个路径并且播放正常:
UIImagePickerControllerMediaURL = "file://localhost/private/var/mobile/Applications/XXXXX-XXXXX/tmp/capture-T0x127bb0.tmp.5gFkOo/capturedvideo.MOV"
但是当 sourceType = Library 时,路径看起来不正确,电影出现在半秒后消失:
UIImagePickerControllerMediaURL = "file://localhost/private/var/mobile/Applications/XXXXX-XXXXX/tmp//trim.ZPeyTU.MOV"
有什么想法吗?
I have strange MPMoviePlayerController behavior. It don't want to play movies just chosen from UIImagePickerController's Camera Roll. But when I capture movie with UIImagePickerController - sometimes it plays in MPMoviePlayerController fine.
This is UIImagePickerController initialization:
mediaPickerController = [[[UIImagePickerController alloc] init] autorelease];
NSArray *types = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
mediaPickerController.sourceType = sourceType;
mediaPickerController.mediaTypes = types;
mediaPickerController.videoQuality = qualityType;
mediaPickerController.delegate = self;
[self presentModalViewController:mediaPickerController animated:YES];
This is - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info delegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *fileURL = [info objectForKey:UIImagePickerControllerMediaURL];
playerView = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[playerView.view setFrame:mediaPreview.bounds];
[playerView setScalingMode:MPMovieScalingModeAspectFit];
[playerView setControlStyle:MPMovieControlStyleEmbedded];
[playerView setShouldAutoplay:NO];
[playerView prepareToPlay];
[mediaPreview addSubview:playerView.view];
}
Another strange issue - when I use UIImagePickerController's sourceType = Camera, then delegate return next path and plays fine:
UIImagePickerControllerMediaURL = "file://localhost/private/var/mobile/Applications/XXXXX-XXXXX/tmp/capture-T0x127bb0.tmp.5gFkOo/capturedvideo.MOV"
but when sourceType = Library, path looks incorrect and movie appears at half second and disappears:
UIImagePickerControllerMediaURL = "file://localhost/private/var/mobile/Applications/XXXXX-XXXXX/tmp//trim.ZPeyTU.MOV"
Have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到了同样的事情,只发生在 iPad 2 上,而同样的代码在 iPhone 4 上运行良好。
事实证明,返回视频后图像选择器没有正确释放。
尝试在 didFinishPickingMediaWithInfo 回调中添加 [picker release]。
I had the same thing, occurring only on the iPad 2, while the same exact code worked fine on an iPhone 4.
It turned out that the image picker wasn't being properly released after returning the video.
Try adding [picker release] in the didFinishPickingMediaWithInfo callback.
这个问题相当不明显。旧版 iPhone 设备在发布媒体选择器后也会尝试删除已保存的文件。因此,为了正确使用它,我之前将其复制到“文档”文件夹(例如),然后将视频设置为电影播放器。
4.3以后的设备没有这个问题。
The issue is pretty non obvious. The older iPhone devices after releasing of media picker tries to delete saved file also. So to use it properly I copy it to Documents folder (for example) before and then set video to movie player.
Devices after 4.3 hasn't this problem.