2014-01-22 2 views
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]; 


} 

답변

0

새로운 self.player를 만들 때 무슨 일이 벌어지고 있습니까?

그냥 머물러 있고 자원을 확실하게 파악하고 있습니다. 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]; 


} 
관련 문제