Get the screenshot of a streaming video on iphone

前端 未结 1 604
面向向阳花
面向向阳花 2020-12-09 06:49

How can i get the screenshot of a streaming video on iphone. I tried several methods.

  1. UIGetScreenImage() -> This is private. The app will be rejected if I u

相关标签:
1条回答
  • 2020-12-09 07:17

    Not sure if it will work, but have you tried using AVPlayer? It should give you access to AVURLAsset which you could pass to AVAssetImageGenerator.

    AVPlayerItem *item = [AVPlayerItem playerItemWithURL:yourURL];
    AVPlayer *player = [AVPlayer playerWithPlayerItem:pItem];
    
    //observe 'status'
    [playerItem addObserver:self forKeyPath:@"status" options:0 context:nil];
    
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                            change:(NSDictionary *)change context:(void *)context
    { 
        if ([keyPath isEqualToString:@"status"]) {
            AVPlayerItem *item = (AVPlayerItem *)object;
            if (item.status == AVPlayerItemStatusReadyToPlay) {
                AVURLAsset *asset = (AVURLAsset *)item.asset;
                AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
                CGImageRef thumb = [imageGenerator copyCGImageAtTime:CMTimeMakeWithSeconds(10.0, 1.0)
                                                          actualTime:NULL
                                                               error:NULL];
            }
        }   
    }
    
    0 讨论(0)
提交回复
热议问题