我有奇怪的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"
有任何想法吗?
答案 0 :(得分:3)
我有同样的事情,只发生在iPad 2上,而相同的代码在iPhone 4上运行良好。
事实证明,在返回视频后,图像选择器未正确释放。
尝试在didFinishPickingMediaWithInfo回调中添加[picker release]。
答案 1 :(得分:1)
问题非常明显。发布媒体选择器后,较旧的iPhone设备也会尝试删除已保存的文件。因此,为了正确使用它,我先将它复制到Documents文件夹(例如),然后将视频设置为电影播放器。 4.3之后的设备没有这个问题。