我有一个图像选择器,我选择一个电影(可以编辑)。然后我使用;
抓取缩略图UIImage *tempImage = [moviePlayerThumb thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
这项工作很好,我可以用另一种方法显示图像没有问题。我还存储了视频数据以便稍后上传;
[mediaDict setValue:[NSData dataWithContentsOfFile:mediaPath] forKey:@"data"];
这也适用于上传文件时服务器没有问题。
我存储的最后一些东西是URL和路径,然而,当我稍后将它们放入播放器中时,我会卡住播放器说“正在加载”(加上spinny东西);
我认为这是因为编辑后的选择器将视频存储在临时目录中(当我稍后播放该文件时)已被清空。
路径是这样的;
file://localhost/private/var/mobile/Applications/B26A085A-C471-4972-9070-5A3F8DC48449/tmp//trim.ttCbAg.MOV
我试图让选择器像这样永久存储视频;
NSString *mediaPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *mediaURL=[info objectForKey:UIImagePickerControllerMediaURL];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (mediaPath))
{
UISaveVideoAtPathToSavedPhotosAlbum (mediaPath, nil, nil, nil);
}
我知道这是有效的,因为我的相册正在慢慢填满我的视频的编辑版本。问题是如何在UISaveVideo方法之后找出文件的路径?
玩家记录此内容;
[MPAVController] Autoplay: Disabling autoplay for pause
[MPAVController] Autoplay: Disabling autoplay
[MPAVController] Autoplay: Disabling autoplay for pause
[MPAVController] Autoplay: Disabling autoplay
[MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
[MPAVController] Autoplay: Enabling autoplay
播放器代码如下所示(我尝试过使用mediaPath和mediaURL);
// Play the movie
NSURL *tempMediaPath = [NSURL fileURLWithPath:images[indexPath.item][@"path"]];
NSURL *tempMediaURL = images[indexPath.item][@"URL"];
NSLog(@"Media Path, URL : %@, %@", tempMediaPath, tempMediaURL);
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:tempMediaPath];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer prepareToPlay];
[moviePlayer play];
和NSLog;
Media Path, URL : file://localhost/private/var/mobile/Applications/B26A085A-C471-4972-9070-5A3F8DC48449/tmp//trim.ttCbAg.MOV, file://localhost/private/var/mobile/Applications/B26A085A-C471-4972-9070-5A3F8DC48449/tmp//trim.ttCbAg.MOV
任何帮助都非常感激。
答案 0 :(得分:1)
您可以更好地将文件移动到您控制的临时文件位置:
NSString *tempFileName = [[NSUUID UUID] UUIDString];
NSURL *location = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:tempFileName];
[[NSFileManager new] moveItemAtURL:tempMovieURL toURL:location error:nil];
答案 1 :(得分:1)
我在另一个项目中做了同样的事情,以下代码在嵌入模式和全屏模式下都有效:
_movieController = [[MPMoviePlayerController alloc] initWithContentURL:self.movieURL];
_movieController.view.frame = self.view.bounds;
_movieController.controlStyle = MPMovieControlStyleEmbedded;
_movieController.backgroundView.hidden = YES;
_movieController.contentURL = self.movieURL;
[_movieController prepareToPlay];
_movieController.scalingMode = MPMovieScalingModeAspectFit;
_movieController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_movieController.shouldAutoplay=YES;
_movieController.movieSourceType = MPMovieSourceTypeFile;
[self.view addSubview:_movieController.view];