我正在加载动态数据,这是一个包含一些描述值和视频网址的字典数组。视频可以是空的,单个或多个URL路径。我正在使用mpmovieplayercontroller
加载视频,而缓冲如果我点击倒带或前进按钮,屏幕变黑,我看不到控件,我必须从后台删除应用程序。有没有办法解决这个问题。
NSURL *fileURL = [NSURL URLWithString:location];
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayerController];
self.moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
self.moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
[self.moviePlayerController prepareToPlay];
[self.moviePlayerController.view setFrame: CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[self.view addSubview:self.moviePlayerController.view];
答案 0 :(得分:2)
这段代码可以帮助您尝试使用以下代码:
-(void) moviePlaybackComplete:(NSNotification*) aNotification
{
MPMoviePlayerController *moviePlayer = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer.view removeFromSuperview];
[self.presentingViewController dismissViewControllerAnimated:YES completion:NULL];
}
这可以帮助您并尝试根据您的要求更改应用
答案 1 :(得分:0)
您正在致电
[self.view addSubview:self.moviePlayerController.view];
每次不删除电影播放器控制器视图时,您都会添加上一次。因此,您的电影播放器控制器视图只是堆叠在一起。而是使用您对旧视图的现有引用将其删除:
NSURL *fileURL = [NSURL URLWithString:location];
if (self.moviePlayerController)
[self.moviePlayerController.view removeFromSuperview];
self.moviePlayerController =
[[MPMoviePlayerController alloc] initWithContentURL:fileURL];
// ... and so on ...
另一条建议:实际上不要打电话
[self.view addSubview:self.moviePlayerController.view];
直到电影准备播放为止。注册告知您的通知,并在收到通知时将视图添加到您的界面:
__block id observer = [[NSNotificationCenter defaultCenter]
addObserverForName:MPMoviePlayerReadyForDisplayDidChangeNotification
object:nil
queue:nil usingBlock:^(NSNotification *note) {
if (self.moviePlayerController.readyForDisplay) {
[[NSNotificationCenter defaultCenter] removeObserver:observer];
[self.view addSubview:self.moviePlayerController.view];
}
}];