0

我想從URL中獲取視頻縮略圖,而不是使用MPMoviePlayerControllerAVAssetImageGenerator。因爲這些有一些問題。問題我已經問,Objective-c,有沒有什麼辦法從URL取代視頻縮略圖,而不是使用MPMoviePlayerController和AVAssetImageGenerator?

1個是:AVAssetImageGenerator not working properly, I am unable to fetch thumbnail of video from URL

和第二點是:https://stackoverflow.com/questions/32431311/mpmovieplayercontroller-not-fetching-thumbnail-of-video-from-url-properly

我不知道該怎麼做。任何建議都會很棒。預先感謝 !!!

回答

0

試試這個。

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:@"[video URL]"] options:nil]; 
AVAssetImageGenerator *generateImg = [[AVAssetImageGenerator alloc] initWithAsset:asset]; 
NSError *error = NULL; 
CMTime time = CMTimeMake(1, 65); 
CGImageRef refImg = [generateImg copyCGImageAtTime:time actualTime:NULL error:&error]; 
NSLog(@"error==%@, Refimage==%@", error, refImg); 

UIImage *FrameImage= [[UIImage alloc] initWithCGImage:refImg]; 
+0

@ Moldaone,我要求從網址取代視頻縮略圖,而不是使用** MPMoviePlayerController和AVAssetImageGenerator **。請給另一個解決方案。謝謝 –

0

所有你需要的是把你的網址下方self.imageView.image = FrameImage;

評論反正。

NSString *[email protected]"https://scontent.cdninstagram.com/hphotos-xfa1/t50.2886-16/11719145_918467924880620_816495633_n.mp4"; 
NSURL *url=[[NSURL alloc]initWithString:str]; 

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil]; 
AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; 
    generator.appliesPreferredTrackTransform=TRUE; 
NSError *error = NULL; 
CMTime thumbTime = CMTimeMakeWithSeconds(0,30); 

CGImageRef refImg = [generator copyCGImageAtTime:thumbTime actualTime:NULL error:&error]; 
if(error) { 
    NSLog(@"%@", [error localizedDescription]); 
} 
UIImage *FrameImage= [[UIImage alloc] initWithCGImage:refImg]; 
[self.imageView setImage:FrameImage]; 
+0

@ Moldaone,請你看看我在問什麼,你在告訴我什麼。請仔細閱讀我的問題+我的最新評論,然後給出答案。謝謝.. –

+0

@Monusingh現在的問題:爲什麼你不想使用AVFoundation? 「AV」有哪些問題? – Moldaone

+0

@ Moldanone,我已經在我的問題中定義了,請參閱我的問題的頂部(本頁),我已經定義了2個問題。謝謝 –

相關問題