ZHChat icon indicating copy to clipboard operation
ZHChat copied to clipboard

Video Preview?

Open GopiK14 opened this issue 6 years ago • 3 comments

Hi team,

Is video preview is already added, Please let me know if any options to loads first frame of video (added_?

Thanks!

GopiK14 avatar May 09 '18 21:05 GopiK14

you can refer to theZHCVideoMediaItem class, it is best to inherit ZHCMediaItem rewrite Method -(UIView *) mediaView, where you can write any view you need to show. The core is the protocol ZHCMessageMediaData you can get to know.

zhuozhuo avatar May 10 '18 01:05 zhuozhuo

Ok Thanks!

GopiK14 avatar May 10 '18 13:05 GopiK14

Refer below:

Class - ZHCMessagesViewController Function - cellforrowatindexpath

     `   id<ZHCMessageMediaData> messageMedia = [messagecell media];
          UIView *view = [messageMedia mediaView] ?:[messageMedia mediaPlaceholderView];if ([[messagecell media] isKindOfClass:[ZHCVideoMediaItem class]]) {
        ZHCVideoMediaItem *v  = (ZHCVideoMediaItem*)[messagecell media];
        NSLog(@"v.fileURL %@",v.fileURL);
        UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        imgV.contentMode = UIViewContentModeScaleAspectFill;
       // imgV.image = [self loadThumbNail:v.fileURL];
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);dispatch_async(queue, ^{
            AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:v.fileURL options:nil];
            AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
            generate.appliesPreferredTrackTransform=TRUE;
            NSError *err = NULL;
            CMTime time = CMTimeMake(1, 60);
            CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];
            NSLog(@"err==%@, imageRef==%@", err, imgRef);
            
            dispatch_sync(dispatch_get_main_queue(), ^{
                // Update UI
                // Example:
                imgV.image = [[UIImage alloc] initWithCGImage:imgRef];
            });
        });
        
        [view addSubview:imgV];
        [view sendSubviewToBack:imgV];

    }`

Thanks!

GopiK14 avatar May 13 '18 11:05 GopiK14