gpt4 book ai didi

iphone - 播放错误时关闭 MPMoviePlayerViewController

转载 作者:行者123 更新时间:2023-12-03 19:16:07 27 4
gpt4 key购买 nike

我的 MPMoviePlayerViewController 存在问题:如果 Controller 在指定的 URL 处找不到电影,它会显示白屏,并且我无法使其关闭。

这就是我启动电影播放器​​的方式:

- (void) playVideo:(NSString*)path 
{
NSURL* url = [NSURL URLWithString:path];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

double osversion = [[[UIDevice currentDevice] systemVersion] doubleValue];
if (osversion >= 3.2)
{
mplayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

if (mplayerVC)
{
mplayerVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[mplayerVC.moviePlayer play];
mplayerVC.moviePlayer.shouldAutoplay = TRUE;

[self presentMoviePlayerViewControllerAnimated:mplayerVC];

//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
}

}
}

这就是 moviePlayBackDidFinish: 方法的样子


- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

NSError* error = [[notification userInfo] valueForKey:@"error"];
if (error != nil)
{
// Movie ended with an error
DLog(@"error=%@", error);
}
else
{
// Movie ended successfully
}

[self dismissMoviePlayerViewControllerAnimated];
SAFE_DEL(mplayerVC);
}

仅当 URL 指向错误时才会出现白屏

最佳答案

别介意伙计们,我已经弄清楚了。

显然在 moviePlaybackDidFinish 方法中你必须调用

[player stop];

在关闭 Controller 之前。

上面,player就是这样获取的MPMoviePlayerController对象:

MPMoviePlayerController *player = [notification object];

关于iphone - 播放错误时关闭 MPMoviePlayerViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4018836/

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