Ios MPMoviePlayer在播放多个视频时不显示
在我的应用程序中,用户可以从摄像机滚动中选择视频并在应用程序中播放。当我第一次选择视频时,一切都很好。但是,当视频结束,我选择另一个视频时,我可以听到音频,但视频控制器从未在屏幕上显示Ios MPMoviePlayer在播放多个视频时不显示,ios,mpmovieplayercontroller,Ios,Mpmovieplayercontroller,在我的应用程序中,用户可以从摄像机滚动中选择视频并在应用程序中播放。当我第一次选择视频时,一切都很好。但是,当视频结束,我选择另一个视频时,我可以听到音频,但视频控制器从未在屏幕上显示 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { self.videoURL = [info objectForKey:UI
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
[self dismissViewControllerAnimated:NO completion:nil];
[self Play];
}
-(void)Play
{
self.player = [[MPMoviePlayerController alloc]initWithContentURL:self.videoURL];
self.player.shouldAutoplay = YES;
self.player.allowsAirPlay = YES;
self.player.view.frame = self.view.frame;
[self.view addSubview: self.player.view];
[self.player setFullscreen:YES animated:YES];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:self.player];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStateChanged:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.player];
[self.player play];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(@"MovieDone");
[self.player.view removeFromSuperview];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.player];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void) exitedFullscreen:(NSNotification*) aNotification {
NSLog(@"MovieDone");
[self.player.view removeFromSuperview];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerDidExitFullscreenNotification
object:self.player];
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[self.navigationController popToRootViewControllerAnimated:YES];
}
当你创建一个新的自我玩家时,你的另一个自我玩家发生了什么 它只是停留在那里,牢牢掌握你的资源。为self.player设置一个新值并不能删除现有的播放器。你的通知中到处都有对它的引用 在开始一个新玩家之前,你应该杀死所有的观察者。像这样:
- (void) movieFinishedCallback:(NSNotification*) aNotification {
NSLog(@"MovieDone");
[self.player.view removeFromSuperview];
[[NSNotificationCenter defaultCenter]removeObserver:self];//kill all the observers here
[self resignFirstResponder];
[self.navigationController popToRootViewControllerAnimated:YES];
}