2014-08-30 81 views

回答

0

您可以用波紋管代碼中創建視頻縮略圖:

-(UIImage *)getThumbNail:(NSString*)stringPath // string path is a path of you video file 
{ 
    NSURL *urlvideoImage =[NSURL fileURLWithPath:stringPath]; 

    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:urlvideoImage 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]; 


// 
    return FrameImage; 
} 
  • 使用上面的代碼從您的視頻URL創建縮略圖。
  • 將此圖像設置爲按鈕背景圖像,或者您可以使用圖像查看並設置點按手勢,忘記它是觸摸事件。
  • 通過點擊按鈕,您可以播放視頻與相關的代碼。希望這是爲你工作。
+0

感謝我得到的略圖,但圖像dosenot適合我imageview.i已經使用這個代碼: - [滾動視圖的Alloc] initWithFrame:方法CGRectMake(0,0,_movieView.bounds.size.width,_movieView.bounds。 size.height)] – apple10 2014-08-30 09:54:51

+0

設置圖像視圖包含模式:yourImageview.contentMode = UIViewContentModeScaleAspectFit; – 2014-08-30 09:56:02