【问题标题】:Play videos automatically on Tableview cell in iOS在 iOS 的 Tableview 单元格上自动播放视频
【发布时间】:2015-10-11 19:06:14
【问题描述】:

我想使用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]];

【问题讨论】:

  • 您能否将您的代码发送到这里,以便我检查并告诉您代码中是否有任何问题。

标签: ios objective-c mpmovieplayer


【解决方案1】:

您需要在 cellForRowAtIndexPath 方法中添加验证以检查 tableview 行运动。使用以下代码检查滚动是否停止。

if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
{
    // Here comes your code for playing/resuming video
}

【讨论】:

    猜你喜欢
    • 2016-04-18
    • 2018-05-28
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 2013-06-18
    • 2016-03-29
    相关资源
    最近更新 更多