[英]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.