ios - 在 iOS 的 Tableview 单元格上自动播放视频

标签 ios objective-c mpmovieplayer

我想使用 MPMoviePlayerTableview 上播放视频。所以我有 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/

相关文章:

objective-c - 如何将 'sender' 发送到 Objective C 中的另一个方法

objective-c - 参数中带有 "="字符的 NSMutableURLRequest

ios - 如何在iOS 8和更高版本中处理RTL语言的后退按钮图像

iphone - MPMoviePlayerController 上的专辑封面

ios - 模拟盲文显示

ios - RestKit 警告 - 警告 : Failed mapping nested object: (null)

objective-c - 是否可以从 Youtube 视频链接播放音频而不是视频?

ios - 检查 HLS 提要是否正在播出

iphone - 启用滑动图像的能力

ios - 在 Swift 3 中使用 Firebase 对 OneSignal 进行身份验证以将自动通知发送到分段