gpt4 book ai didi

iphone - 单击“完成”时 MPMoviePlayerController 不会删除 View

转载 作者:行者123 更新时间:2023-12-03 18:38:40 24 4
gpt4 key购买 nike

我正在创建一个 MPMoviePlayerController 对象并以全屏模式流式传输视频。

我正在使用 UIViewController 来显示电影 View 。

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//http://www.youtube.com/watch?feature=player_detailpage&v=ebeQaznNcmE
NSURL *url = [NSURL URLWithString:@"http://a1408.g.akamai.net/5/1408/1388/2005110405/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_mpeg4.mp4"];
MPMoviePlayerController *mPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
mPlayer.view.frame = gMainView.frame;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mPlayer];
mPlayer.shouldAutoplay = YES;
mPlayer.controlStyle = MPMovieControlStyleFullscreen;
[gMainView addSubview:mPlayer.view];
[mPlayer prepareToPlay];
[mPlayer setFullscreen:YES animated:YES];
[mPlayer play];
}


- (void)moviePlayBackDidFinish:(NSNotification*)notification {
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
//movie finished playing
}
else if (reason == MPMovieFinishReasonUserExited) {
//user hit the done button
MPMoviePlayerController *moviePlayer = [notification object];

[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
[moviePlayer release];
}
else if (reason == MPMovieFinishReasonPlaybackError) {
//error
}
}

单击完成后,视频视觉对象将从屏幕上删除,但控件不会从屏幕上删除, View 也不会从屏幕上删除。

控件确实出现“//用户点击完成按钮”。它确实执行代码以从 super View 中删除 View ,我通过添加日志进行了检查,但是控件没有从屏幕上删除, View 也没有从屏幕上删除。我做错了什么?

编辑:

如果我使用 MPMoviePlayerViewController 那么它甚至不会等待我按“完成”。视频完成后,它会自动删除 View 。但我不想要这样。

编辑:

如果我删除“[mPlayer setFullscreen:YESanimated:YES]”,那么当单击“完成”时, View 将被完全删除。但视频没有全屏显示,状态栏变成灰色,这又是我不想要的。

最佳答案

以下代码对我有用,希望对您也有帮助。

-(IBAction)playVedio:(id)sender{
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setUseApplicationAudioSession:NO];
[[mp moviePlayer] setShouldAutoplay:YES];
[[mp moviePlayer] setControlStyle:2];
[[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self presentMoviePlayerViewControllerAnimated:mp];

}

-(void)videoPlayBackDidFinish:(NSNotification*)notification {

[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[mp.moviePlayer stop];
mp = nil;
[mp release];
[self dismissMoviePlayerViewControllerAnimated];
}

关于iphone - 单击“完成”时 MPMoviePlayerController 不会删除 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9564419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com