我有一个应用程序,我想在应用程序内显示来自urls
的视频。
我正在使用MPMoviePlayerViewController
。
以下是我正在使用的代码,但不知何故视频未在urls
播放。
NSURL *URL = [NSURL URLWithString:@"http://vimeo.com/81889151"];
playercontroller = [[MPMoviePlayerViewController alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishvideo:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[playercontroller.moviePlayer setContentURL:URL];
[self.view addSubview:playercontroller.view];
我搜索了很多,但找不到适合我的正确解决方案。
上面的代码出了什么问题?
请帮助我。
任何帮助将不胜感激。
提前致谢。
答案 0 :(得分:2)
您要加载的网址是标准网页。 您需要加载iOS接受的格式,如h264。您可以在UIWebView中显示此影片。现在,MPMoviePlayer正在尝试加载一个HTML网页,由于显而易见的原因,该网页无效。
在UIWebView中加载视频的方法如下:
NSString *htmlString = @"<iframe src=\"//player.vimeo.com/video/81889151\" width=\"100%\" height=\"100%\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";
UIWebView *webView = [[UIWebView alloc] initWithFrame:FRAME];
[webView loadHTMLString:htmlString baseURL:nil];
[self.view addSubview:webView];
答案 1 :(得分:0)
[self.view.layer addSublayer:playercontroller];
[playercontroller play];
试试这个
答案 2 :(得分:0)
@interface VideoViewController : UIViewController <MPMediaPickerControllerDelegate>
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
@end
NSURL *movieURL = [NSURL URLWithString:@"http://vimeo.com/81889151"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishvideo:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:NO];
答案 3 :(得分:0)
尝试呈现电影播放器视图控制器
,而不是添加为子视图NSURL *URL = [NSURL URLWithString:@"http://vimeo.com/81889151"];
playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:URL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(finishvideo:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self presentMoviePlayerViewControllerAnimated:playercontroller];