在iOS中播放视频失败

在iOS中播放视频失败,ios,objective-c,video,mpmovieplayercontroller,Ios,Objective C,Video,Mpmovieplayercontroller,我只想加载主捆绑包中的一个视频文件,这似乎很简单,但由于某些原因,我不断收到MPMoviePlayerController的错误,我有以下代码 - (void)viewDidLoad{ [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"ipad2" ofType:@"mp4"]; self.myPlayer = [[MPMoviePlayerController alloc] init

我只想加载主捆绑包中的一个视频文件,这似乎很简单,但由于某些原因,我不断收到
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(非原子,强)MPMoviePlayerController*myPlayer

我在iOS 6上运行,这些都发生在设备和模拟器上

NSString *path = [[NSBundle mainBundle] pathForResource:@"ipad2" ofType:@"mp4"];
您是否在调试器中检查了
path
不是
nil

self.myPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];

这是从文件路径创建URL的错误方法。改为使用。

我还使用MPMoviePlayerViewController在我的应用程序上进行视频直播,并获得了相同的上述错误列表。我发现MPMoviePlayer不支持使用较大的数据来显示视频,但如果使用较小的视频数据,则工作正常,不会给出任何错误。事实上,这并不是电影播放器准备播放和播放性能的问题

如果需要显示更大的数据,请在应用程序上使用webview