2

私はここに新しいです。私はすでに2日間解決策を閲覧していますが、不満です.

これが私のコードです:

NSString *docPath = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *docaPathFull = [docPath stringByAppendingPathComponent:@"/IMG_0003.m4v"];
self.videoURL = [NSURL fileURLWithPath:docaPathFull];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage  *thumbnail = [player thumbnailImageAtTime:4.0 timeOption:MPMovieTimeOptionExact];
player = nil;       
self.imageView.image = thumbnail;

問題は、MPMoviePlayerController でビデオ ファイルを表示できないことです。サムネイルを取得できず、再生できません。黒いプレーヤーとロード無限大だけです。

私は試しました:

NSString*thePath=[[NSBundle mainBundle] pathForResource:@"IMG_0003" ofType:@"m4v"];
self.videoURLtheurl=[NSURL fileURLWithPath:thePath];

この

self.videoURL = [[NSBundle mainBundle] URLForResource:@"IMG_0005" withExtension:@"mov"];

この

NSString *filePath = @"/Users/[user]/Documents/video/IMG_0004.mov";
self.videoURL = [NSURL fileURLWithPath:filePath];

私の命を救う方法があれば教えてください!!!

ありがとうございました。

4

3 に答える 3

0

次のメソッドを使用して、特定のビデオ URL のサムネイル画像を取得できます。

    -(UIImage *) giveThumbofVideoUrl:(NSURL *) url{
            NSString *urlString = [url absoluteString];
            AVAsset *asset = [AVAsset assetWithURL:url];
            AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
            imageGenerator.appliesPreferredTrackTransform = YES;
            //imageGenerator.maximumSize = CGSizeMake(320,480);
            CMTime time = CMTimeMake(1, 1);
            CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
            UIImage *image = [UIImage imageWithCGImage:imageRef];
            CGImageRelease(imageRef);
    return image;
   }

どのように使用できますか?,

NSString*thePath=[[NSBundle mainBundle] pathForResource:@"IMG_0003" ofType:@"m4v"];
NSURL *movieUrl=[NSURL fileURLWithPath:thePath];
UIImage  *thumbnail = [self giveThumbofVideoUrl:movieUrl];
于 2013-05-02T14:05:56.510 に答える
0

MPMoviePlayerController現在非推奨です。だから私は使用しAVPlayerViewControllerました。そして次のコードを書きました:

NSURL *videoURL = [NSURL fileURLWithPath:filePath];
    //filePath may be from the Bundle or from the Saved file Directory, it is just the path for the video
    AVPlayer *player = [AVPlayer playerWithURL:videoURL];
    AVPlayerViewController *playerViewController = [AVPlayerViewController new];
    playerViewController.player = player;
    //[playerViewController.player play];//Used to Play On start
    [self presentViewController:playerViewController animated:YES completion:nil];

次のフレームワークをインポートすることを忘れないでください:

#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>

お役に立てれば..

于 2015-10-01T13:59:59.523 に答える