0

我有一个图像选择器,我可以在其中选择一部电影(可以编辑)。然后我使用缩略图;

UIImage *tempImage = [moviePlayerThumb thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];

这工作正常,我可以用另一种方法显示图像没有问题。我还存储视频数据以供稍后上传;

[mediaDict setValue:[NSData dataWithContentsOfFile:mediaPath] forKey:@"data"];

这也适用于一旦上传文件从服务器播放没有问题。

我存储的最后一件事是 URL 和路径,但是,当我稍后将它们放入播放器时,我会卡住播放器说“正在加载”(加上旋转的东西);

我认为这是因为编辑后的选择器将视频存储在一个临时目录中(当我稍后播放文件时)已被清空。

路径是这样的;

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

任何帮助都非常感谢。

4

2 回答 2

1

您可以更好地将文件移动到您控制的临时文件位置:

NSString *tempFileName = [[NSUUID UUID] UUIDString];
NSURL *location = [[NSURL fileURLWithPath:NSTemporaryDirectory()] URLByAppendingPathComponent:tempFileName];

[[NSFileManager new] moveItemAtURL:tempMovieURL toURL:location error:nil];
于 2013-07-16T15:51:26.063 回答
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];
于 2013-07-17T08:27:04.923 回答