我想使用 MPMoviePlayer
在 Tableview
上播放视频。所以我有 10 个视频,我需要在 tableview 上加载视频。所以在 tableview 上滚动时,不想播放视频。一旦 tableview 滚动完成,当前可见的单元格索引视频需要在单元格内自动播放。我该如何实现?
请参阅下面的每个单元格的代码,
[self.players.view removeFromSuperview];
NSURL *videoURL = [NSURL URLWithString:str_videourl];
self.players = [[MPMoviePlayerController alloc]init];
[self.players.view setFrame:videoView.frame];
self.players.controlStyle = MPMovieControlStyleEmbedded;
self.players.shouldAutoplay = YES;
self.players.movieSourceType = MPMovieSourceTypeStreaming;
[self.players setContentURL:videoURL];
self.players.scalingMode = MPMovieScalingModeAspectFill;
self.players.view.tag=indexPath.section;
[cell.viewBase addSubview:self.players.view];
[self.players prepareToPlay];
[self.players.view setBackgroundColor:[UIColor clearColor]];
最佳答案
您需要在 cellForRowAtIndexPath 方法中添加验证以检查表格 View 行的移动。使用以下代码检查滚动是否停止。
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
{
// Here comes your code for playing/resuming video
}
关于ios - 在 iOS 的 Tableview 单元格上自动播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31554111/