首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVPlayerViewController没有播放视频

AVPlayerViewController没有播放视频
EN

Stack Overflow用户
提问于 2017-05-04 13:16:16
回答 1查看 74关注 0票数 0

下面的代码不工作

代码语言:javascript
复制
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];

NSURL *url = [NSURL URLWithString:@"http://54.254.248.1/app/webroot/uploads/question_files/2017.04.20.13.43.45video.mp4"];

AVURLAsset *asset = [AVURLAsset assetWithURL: url];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];

AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem: item];

playerViewController.player = player;
[playerViewController.view setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width)];

playerViewController.showsPlaybackControls = YES;

[self.view addSubview:playerViewController.view];

[player play];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-04 13:44:18

我像这样修改您的代码,它可以工作:

代码语言:javascript
复制
NSURL *url = [NSURL URLWithString:@"http://54.254.248.1/app/webroot/uploads/question_files/2017.04.20.13.43.45video.mp4"];
AVPlayer * player = [AVPlayer  playerWithURL:url];

AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];

playerViewController.player = player;
[playerViewController.view setFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width)];

playerViewController.showsPlaybackControls = YES;

[self.view addSubview:playerViewController.view];

[player play];

有关AVPlayerViewController的更多信息

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43783971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档