我正在尝试在我的网站上播放 mp4 视频。
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://mywebsite.com/video.mp4"]];
moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
moviePlayer.moviePlayer.shouldAutoplay=YES;
moviePlayer.moviePlayer.movieSourceType= MPMovieSourceTypeFile;
[moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleDefault];
[self.view addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];
它没有播放视频并出现此错误:
2013-12-08 22:31:00.497 UIWebViewVideoArge[684:60b] _itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
最佳答案
代码中的网址:http://mywebsite.com/video.mp4
- 无效。使用此 url 播放器会产生与您的问题类似的错误。但是如果您尝试使用另一个 url(例如:http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4
- 将其用于测试)您的播放器将正常工作,但不正确。为了正确工作,您必须更改代码:
在 @interface
部分属性中添加到您的 .h
文件(不要忘记添加 @import MediaPlayer
):
@property (nonatomic, strong) MPMoviePlayerViewController *moviePlayer;
并像下面这样更改您的代码:
_moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"]];
_moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
_moviePlayer.moviePlayer.shouldAutoplay=YES;
_moviePlayer.moviePlayer.movieSourceType= MPMovieSourceTypeFile;
[_moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleDefault];
[self.view addSubview:_moviePlayer.view];
[_moviePlayer.moviePlayer play];
作为替代方案,您可以使用 UIWebView
播放视频:
NSURL *fileURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];
NSURLRequest* requestUrl = [[NSURLRequest alloc] initWithURL:fileURL];
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
[self.view addSubview:webView];
[webView loadRequest:requestUrl];
如果您将使用 UIWebView
播放视频 - 尝试使用您的 url,您将看到您的链接有什么问题。
关于ios - MPMoviePlayerViewController 没有从 url 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20458711/