【问题标题】:play multiple videos smoothly in CollectionView like Facebook在 Facebook 等 CollectionView 中流畅播放多个视频
【发布时间】:2017-01-05 05:36:49
【问题描述】:

我正在尝试在 Collection 单元格的每一行中实现一个 AVPlayer,但我没有找到任何好的文档。知道在哪里可以找到一些吗?

【问题讨论】:

标签: objective-c xcode8 avplayer avplayerviewcontroller


【解决方案1】:

试试这个代码

self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"something" ofType:@"mp4"]]];
[self.moviePlayer.view setFrame:CGRectMake(0, 0, 320, 320)];
[self.moviePlayer play];
[self.view addSubview:self.moviePlayer.view];
  • self.movi​​eplayer 是 MPMoviePlayerController(不是 MPMoviePlayerViewController)的一个实例。根据我的经验,将其声明为属性(例如:@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;)而不是简单的 ivar 很重要,因为有时如果它是 ivar,它就不起作用
  • 设置帧也很重要,因为如果我们不设置,视频根本不会出现。框架可以是任何东西,只要您定义的内容在您的视图范围内即可
  • 重要提示:如上,在定义 URL 时,如果您想通过网络访问文件,请使用 NSURL 的 URLWithString 方法,如果您在本地有文件,请使用 NSURL 的 fileUrlWithPath!

【讨论】:

    猜你喜欢
    • 2015-09-28
    • 2011-12-10
    • 2021-12-05
    • 1970-01-01
    • 2013-08-08
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多