MPMoviePlayerController无法从远程URL播放视频

时间:2017-03-25 09:00:08

标签: ios iphone mpmovieplayercontroller

如果我在浏览器中点击了以下网址,它会播放视频,但我的以下代码不会在iPhone上播放。

http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4

MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4"]];

moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
这是iPhone的屏幕截图。 enter image description here

3 个答案:

答案 0 :(得分:0)

不推荐使用MPMoviePlayerController。您可以改用AVPlayer。

AVPlayer *player = [AVPlayer playerWithURL:"URL"];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
controller.player = player;
[player play];

答案 1 :(得分:0)

您需要告诉MPMoviePlayerController它需要流式传输视频。只需添加以下行:

moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

答案 2 :(得分:0)

是的,您必须将其流媒体网址告知:

moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;

然后准备玩

[moviePlayer prepareToPlay];