我试图通过按下按钮在iPhone上播放来自互联网的视频流。我使用了很多代码示例,但没有任何效果。使用这段代码时,它打开一个黑色视图,没有任何视频流或控制器。(视频流本身可以工作。)
NSURL *url = [NSURL URLWithString:@"http://MyStreamURL.com"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
presentMoviePlayerViewControllerAnimated
而不是presentModalViewController
。这将产生适当的动画效果,符合用户对电影播放器的期望。 - Till