Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Preview? #58

Open
GopiK14 opened this issue May 9, 2018 · 3 comments
Open

Video Preview? #58

GopiK14 opened this issue May 9, 2018 · 3 comments

Comments

@GopiK14
Copy link

GopiK14 commented May 9, 2018

Hi team,

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

Thanks!

@zhuozhuo
Copy link
Owner

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.

@GopiK14
Copy link
Author

GopiK14 commented May 10, 2018

Ok Thanks!

@GopiK14
Copy link
Author

GopiK14 commented May 13, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants