【发布时间】:2016-03-16 23:38:41
【问题描述】:
我有 youtube 自动播放的代码,但现在要求是在自动播放中播放 Vimeo 视频。我曾经在目标 c 中编写代码,你能给出任何符合这个要求的示例代码吗? 注意:我使用第三方工具名称为“MPMoviePlayerViewController”
【问题讨论】:
标签: ios objective-c iphone vimeo vimeo-ios
我有 youtube 自动播放的代码,但现在要求是在自动播放中播放 Vimeo 视频。我曾经在目标 c 中编写代码,你能给出任何符合这个要求的示例代码吗? 注意:我使用第三方工具名称为“MPMoviePlayerViewController”
【问题讨论】:
标签: ios objective-c iphone vimeo vimeo-ios
MPMoviePLayerViewController 类在 iOS 9 中已被弃用。Apple 建议改用 AVPLayerViewController - 它适用于本地和远程 URL。
在 Objective-C 中如何使用它:
// grab your remote URL
NSURL *videoURL = [NSURL URLWithString:@"http://domain.com/video.mp4"];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];
// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;
您必须将 AVFoundation 和 AVKit 导入您的课程才能成功。
【讨论】: