我只想加载主包中的视频文件,这看起来很简单,但由于某种原因,我不断收到错误MPMoviePlayerController
,我有以下代码。
- (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
未定义的 loadState。
这是一个带有任何其他方法的简单 viewController,我在.h
文件中有这些声明:
@property (nonatomic, strong) MPMoviePlayerController *myPlayer;
我在 iOS 6 上运行,这些都发生在设备和模拟器中