[英]AVPlayerViewController not playing video and showing Quicktime logo
我正在尝试使用XCode 6中引入的新AVPlayerViewController播放视频。
要播放视频,我已经完成了此设置。
使用本地mp4文件播放视频
扩展的AVPlayerViewController
播放器设置代码:
-(void)setupPlayer
{
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"exodus_trailer" ofType:@"mp4"];
NSLog(@"File Path : %@",filePath);
AVAsset *avAsset = [AVAsset assetWithURL:[NSURL URLWithString:filePath]];
AVPlayerItem *avPlayerItem =[[AVPlayerItem alloc]initWithAsset:avAsset];
self.player = [[AVPlayer alloc]initWithPlayerItem:avPlayerItem];
[self.player addObserver:self forKeyPath:@"status" options:0 context:nil];
[self.player play];
}
KVO处理:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self.player && [keyPath isEqualToString:@"status"])
{
if (self.player.status == AVPlayerStatusFailed)
{
NSLog(@"AVPlayer Failed");
}
else if (self.player.status == AVPlayerStatusReadyToPlay)
{
NSLog(@"AVPlayerStatusReadyToPlay");
[self.player play];
}
else if (self.player.status == AVPlayerItemStatusUnknown)
{
NSLog(@"AVPlayer Unknown");
}
}
}
问题 :
KVO日志正在打印AVPlayerStatusReadyToPlay,文件路径似乎正常。 以前的视图至少显示了具有所有默认控件的播放器,但是现在没有任何更改,它开始显示没有任何控件的Quick time logo。 显示此徽标是什么意思? 我在这里做错了什么?
屏幕截图:
这与您想做的完全一样。 代码的问题是您没有使用文件路径,请使用它来加载文件路径NSURL * url = [NSURL fileURLWithPath:urlString]
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlString = [[NSBundle mainBundle] pathForResource:@"testfile" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlString];
self.player = [[AVPlayer alloc] initWithURL:url];
[self.player addObserver:self forKeyPath:@"status"
options:NSKeyValueObservingOptionNew
context:NULL];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self.player) {
AVPlayerStatus status = [change[NSKeyValueChangeNewKey] integerValue];
if (status == AVPlayerStatusReadyToPlay) {
[self.player play];
[self.player removeObserver:self forKeyPath:@"status"];
}
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
@end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.