当我尝试在Xcode项目上保存的视频时,它有效。 然后,当我用url更改它时,它总是返回此错误:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
这是我的代码:
NSURL *url = [NSURL fileURLWithPath:@"https://m.youtube.com/watch?v=9MNAeGWd_04"];
movieController = [[MoviePlayerVC alloc]initWithContentURL:url];
movieController.view.frame = self.view.bounds;
[movieController.moviePlayer setShouldAutoplay:YES];
[movieController.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[[movieController view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
[self presentViewController:movieController animated:NO completion:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateDidChange:)
name:@"MPAVControllerPlaybackStateChangedNotification"
object:nil];
答案 0 :(得分:1)
fileURLWithPath:
需要本地路径网址 - /User/blah/blah.mp3
尝试使用[NSURL URLWithString:@"https://m.youtube.com/watch?v=9MNAeGWd_04"]
答案 1 :(得分:1)
如果你从URL播放,那么尝试
-(void)playFromLiveUrl
{
NSURL *aUrl = [NSURL URLWithString:@"*YOUR URL*"];
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:aUrl];
_moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.view.frame = asyvideoImage.frame;
_moviePlayer.scalingMode=MPMovieScalingModeFill;
[self.view addsubview _moviePlayer.view];
[_moviePlayer prepareToPlay];
[_moviePlayer setFullscreen:NO animated:NO];
}
如果您使用本地文件,则使用此
-(void)playFromLocal
{
_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:@"** LOCAL PATH ** "]];
_moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayer.shouldAutoplay = YES;
_moviePlayer.view.frame = asyvideoImage.frame;
_moviePlayer.scalingMode=MPMovieScalingModeFill;
[self.view addsubview _moviePlayer.view];
[_moviePlayer prepareToPlay];
[_moviePlayer setFullscreen:NO animated:NO];
}
答案 2 :(得分:1)
MPMoviewPlayerController
无法获取您的格式。您尝试使用youTube链接加载MPMoviePlayerController
,它将无效(正如您所见):
Here你可以找到iPhone视频格式支持。
尝试加载MoviePlayer
这样的内容(例如.m3u8
格式):
[movieController setContentURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"]];
答案 3 :(得分:0)
MPMoviePlayerController
无法播放Flash Youtube网址。请改用Web视图。 iOS上的UIWebView足够智能播放youtube内容。
您可以看到视频格式MPMoviePlayer
和AVFoundation
支持here