我想使用MPMoviePlayerController播放mp4视频文件。 这是我目前使用的代码:
NSURL *url = [NSURL URLWithString:
videoLink];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc ]init];
[controller`enter code here` prepareToPlay];
self.mp = controller; //Save obj reference
此外,我正在使用相同的播放器对象,因为必须在下一次或之前点击UI时加载另一个视频文件。
controller.view.frame = CGRectMake(0, yMargin, self.view.frame.size.width, self.view.frame.size.width*9/16); //Set the size
[self.view addSubview:controller.view];//Show the view
[controller setContentURL:url];
[controller play]; //Start playing
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:self.mp ];
有时它会正确加载视频,但会随机显示错误消息,如下所示。
itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
If error comes it doesn't load any other video afterwards at least for next 15(approx.) attempts.This behaviour is very random as sometimes it keeps showing the error in log and player doesn't load the video at all.
其他人是否遇到过类似的问题?我发现很多问题与这个问题有关,但似乎没有什么对我有用。
其他解决方案我发现使用网络视图播放视频但自动播放 不适用于Web视图。