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

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


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

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


这也可以工作,因为一旦上传文件就不会从服务器出现问题。

我存储的最后一件事是URL和Path,但是,当我稍后将它们放入播放器中时,我被播放器说“正在加载”(加上棘手的东西)困住了;

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

路径是这样的;

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


任何帮助真的很感激。

最佳答案

我在另一个项目中也做了同样的事情,以下代码在嵌入式模式和全屏模式下都可以工作:

_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];

关于ios - 在UIImagePicker和UISaveVideoAtPathToSavedPhotosAlbum之后找到mediaPath,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17681002/

10-10 23:26