Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:截图展示ipad视频_Ios_Xcode_Video_Avplayer_Avplayerlayer - Fatal编程技术网

iOS:截图展示ipad视频

iOS:截图展示ipad视频,ios,xcode,video,avplayer,avplayerlayer,Ios,Xcode,Video,Avplayer,Avplayerlayer,我试图拍摄播放视频的截图,但截图总是显示空白。这是我的代码: UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContex

我试图拍摄播放视频的截图,但截图总是显示空白。这是我的代码:

UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *data = UIImageJPEGRepresentation(viewImage, 1.0);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.jpg"];
    [data writeToFile:filePath atomically:YES];
我正在使用AVPlayer/AVPlayerLayer来播放视频

你们谁知道为什么会这样?或者,如果我需要做一些特殊的视频,以便能够采取截图


非常感谢您的帮助。

我找到了解决问题的方法:

AVAssetImageGenerator *imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:[self.player.currentItem asset]];
    CGImageRef ref = [imageGenerator copyCGImageAtTime:self.player.currentItem.currentTime actualTime:nil error:nil];
    UIImage *viewImage = [UIImage imageWithCGImage:ref];
    CGImageRelease(ref);
    NSData *data = UIImageJPEGRepresentation(viewImage, 1.0);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.jpg"];
    [data writeToFile:filePath atomically:YES];

它显示了除了视频以外的一切