在UITableViewCell中播放视频的最佳方法是什么 [英] What is the best way to play video in UITableViewCell

查看:87
本文介绍了在UITableViewCell中播放视频的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据单元格位置在 UITableViewCell 中自动播放视频.

I'm trying to make auto-play video in UITableViewCell depending on cell position.

我正在使用 AVPlayer

这是我的代码:

    __weak typeof(self)this = self;

    NSString* videoPath = @"http://test.com/test.mp4";
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:videoPath] options:nil];
    NSArray* keys = [NSArray arrayWithObjects:@"playable",nil];

    [asset loadValuesAsynchronouslyForKeys:keys completionHandler:^(){
        AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:asset];
        this.avPlayer = [AVPlayer playerWithPlayerItem:playerItem];
        this.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:this.avPlayer];
        this.avPlayerLayer.frame = _videoContent.frame;

        dispatch_async(dispatch_get_main_queue(),^{
            [this.videoContent.layer addSublayer:this.avPlayerLayer];
            [this.avPlayer play];
        });
    }];

但是当我滚动表格时,我的UITableView被冻结了. 我认为有很多耗时的工作,但是最大的事情是

But my UITableView is frozen when i scroll the table. I think there are many time-consuming work but most biggest thing is

[this.avPlayer play]

所以我的问题是,在这种情况下,AVPlayer是最好的方法吗? 有什么方法可以提高性能吗?

So my question is that AVPlayer is the best way in this situation? And is there any way to improve the performance?

推荐答案

使用下面的链接,适合您的问题.

Use the below link , this suits for your question.

https://github.com/PRX/PRXPlayer

这篇关于在UITableViewCell中播放视频的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆