0
在我的應用程序中,用戶可以從相機膠捲中選擇一個視頻並在應用程序中播放。當我第一次選擇一個視頻時,一切都很好。但是,當視頻結束並且我去選擇另一個視頻時,我可以聽到音頻,但視頻控制器從不在屏幕上顯示。MPMoviePlayer在播放多個視頻時不會顯示
-(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];
}