Qual é a melhor maneira de reproduzir vídeo no UITableViewCell
Estou tentando fazer a reprodução automática de vídeoUITableViewCell dependendo da posição da célula.
Estou usando oAVPlayer
Aqui está o meu código:
__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];
});
}];
Mas meu UITableView fica congelado quando eu rolar a tabela. Eu acho que há muito trabalho demorado, mas a maior coisa é
[this.avPlayer play]
Então, minha pergunta é que o AVPlayer é a melhor maneira nessa situação? E existe alguma maneira de melhorar o desempenho?