gpt4 book ai didi

ios - MPMoviePlayer 未从 super View 中删除

转载 作者:行者123 更新时间:2023-12-03 17:24:20 27 4
gpt4 key购买 nike

我使用以下代码在 MPMoviePlayerController 中播放视频文件

  NSString* filePath = [[NSBundle mainBundle] pathForResource:@"one" ofType:@"mp4"];
NSURL* url = [NSURL fileURLWithPath:filePath];

_movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
[_movie.view setFrame:self.view.bounds];
[self.view addSubview:_movie.view];
_movie.fullscreen=YES;
_movie.controlStyle=MPMovieControlStyleFullscreen;
[_movie prepareToPlay];
[_movie play];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(close:)name:MPMoviePlayerPlaybackDidFinishNotification object:_movie];

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

int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];

if(reason == MPMoviePlaybackStateStopped) {

NSLog(@"Stop");

}
else if (reason == MPMovieFinishReasonPlaybackEnded) {
NSLog(@"Playback Ended ");
}
else if (reason == MPMovieFinishReasonUserExited) {

NSLog(@"Exited");
[_movie.view removeFromSuperview];
}
else if (reason == MPMovieFinishReasonPlaybackError) {
//error
NSLog(@"Error");
}
}

我能够收到通知,并且电影播放器​​没有从 super View 中删除。

可能是什么问题?

最佳答案

按照说明尝试:

当我听 MPMoviePlayerWillExitFullscreenNotification 时。

[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(doneButtonClick:)
name:MPMoviePlayerWillExitFullscreenNotification
object:_movie];

和选择器方法:

-(void)doneButtonClick:(NSNotification*)aNotification{
[_movie.view removeFromSuperview];
}

(或)

在下面的教程中使用 mpmovieplayerviewcontroller 的更好方法

http://mobiledevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

关于ios - MPMoviePlayer 未从 super View 中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11359451/

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