我正在编写一种简单的方法来全屏启动流媒体视频并让用户退出按“完成”按钮。问题是,我无法删除MPMediaPlayerController视图,或者我做错了。
- (IBAction)playVideoButtonPressed:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://mysite.com/video.mov"];
mp = [[MPMoviePlayerController alloc] initWithContentURL: url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerPlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
if ([mp respondsToSelector:@selector(setFullscreen:animated:)]) {
mp.controlStyle = MPMovieControlStyleFullscreen;
mp.shouldAutoplay = YES;
[self.view addSubview:mp.view];
[mp.view setTag:3];
[mp setFullscreen:YES animated:YES];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mp];
[mp play];
}
- (void)moviePlayBackDidFinish:(id)sender {
NSLog(@"Quitting MoviePlayer");
[mp.view removeFromSuperview];
}
我们的想法是点击应用程序中的按钮调用MPMediaPlayerController视图,点击“完成”视频或视频结束时将其解除。
答案 0 :(得分:0)
我应该使用MPMoviePlayerViewController。