我只是想加載一個主包中的視頻文件,這看起來很簡單,但由於某種原因我不斷收到MPMoviePlayerController
的錯誤,我有以下代碼。在iOS中播放視頻失敗
- (void)viewDidLoad{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"ipad2" ofType:@"mp4"];
self.myPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
[self.myPlayer prepareToPlay];
self.myPlayer.movieSourceType = MPMovieSourceTypeFile;
[self.myPlayer.view setFrame:self.view.bounds];
[self.view addSubview:self.myPlayer.view];
[self.myPlayer play];
}
我只得到一個黑色的屏幕和下面的輸出:
2013-01-09 13:38:15.686 myVideoApp[1789:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-01-09 13:38:15.690 myVideoApp[1789:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
我也嘗試添加這些通知玩,但是永遠不會發送:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(playVideo:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:self.myPlayer ];
當我打印self.myPlayer.loadState
我得到了0
這是undefined loadState。
這些是一個簡單的viewController與任何其它方法,並且我對.h
文件這些聲明: @property (nonatomic, strong) MPMoviePlayerController *myPlayer;
我真的在iOS 6運行,並且這些可以同時在設備和模擬器
感謝改變創建URL的方式解決了這個問題 –