我正在尝试在我的网站上播放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;
}
答案 0 :(得分:2)
代码中的网址:http://mywebsite.com/video.mp4
- 无效。使用此url播放器会产生类似于您的问题的错误。但是,如果您尝试使用其他网址(例如:http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4
- 使用它进行测试),您的播放器将无错误地工作,但不正确。为了正确工作,您必须更改代码:
添加到.h
部分属性中的@interface
文件(不要忘记添加@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
播放视频 - 尝试使用您的网址,您会看到您的链接错误。