2010-07-22 6 views
3

iOS4 for iPhone 4/3GS에서 tableview가 있고 셀 중 하나가 동영상 파일을 재생합니다. 동영상 재생이 끝나고 컨트롤이 사라지면 상태 막대 아래에서보기가 다시 나타납니다. 이 이미지에서와 마찬가지로 ... 나는 너무 새로 게시 할 수 없습니다. 컨트롤이 영화가 끝날 때에있는 경우, 문제가없는동영상 완료 후 MPMoviePlayerViewController 문제

http://www.dezignwright.com/ios4_movie.png

... 여기를 참조하십시오.

보너스 : 재생을 시작할 때 동영상 플레이어를 가로로 놓으려면 어떻게해야합니까? 나는 초상화에서 전혀 놀고 싶지 않다.

감사합니다.

답변

0

이것은 4.0의 버그 인 것 같습니다. "완료"버튼을 사용하여 종료 할 때 제대로 작동합니다.

제가 사용하는 해결 방법은 수동으로 프레임을 저장 한 다음 MPMoviePlayerPlaybackDidFinishNotification을받을 때 복원하는 것입니다. 마지막으로

은 가로 모드에서 그것을 얻을 재정의 MPMoviePlayerViewController의 서브 클래스를 사용하는 shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

즉, 이 같은 :

@interface CustomMoviePlayerViewController : MPMoviePlayerViewController 
@end 
@implementation CustomMoviePlayerViewController 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft; 
} 
@end 

그리고 컨트롤러에

이 버그를 해결하기 위해 : 나는 명시 적으로 내가 방금 전에 내 원래보기에 전체 화면 레이아웃을 사용하지 않는 것이 선언함으로써이 문제를 해결했다

- (void)playbackEnded:(NSNotification *)notification 
{ 
    [[self view] setFrame:[self originalFrame]]; 
} 

- (void)playMovie:(NSString *)movieURLString 
{ 
    MPMoviePlayerViewController *controller = [[CustomMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movieURLString]]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackEnded:) name:MPMoviePlayerPlaybackDidFinishNotification object:[controller moviePlayer]]; 
    [self presentMoviePlayerViewControllerAnimated:controller]; 
} 
+0

감사합니다 !!! 나는 그것을 시도 할 것이다. –

+0

효과가 있었나요? – Nuoji

+0

여전히 문제가있는 경우 내 솔루션을 살펴보십시오 – Sid

0

나는 동영상 플레이어 시작 :

-(IBAction)playMovieButtonPressed:(id)sender { 
    MPMoviePlayerViewController* playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[self localMovieURL]]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
      selector:@selector(playbackDidFinish:) 
      name:MPMoviePlayerPlaybackDidFinishNotification 
       object:playerViewController.moviePlayer]; 

[self setWantsFullScreenLayout:NO]; 
// this ensures that the original frame is restored correctly 
// if the movie ends and the player is closed automatically 

[self presentMoviePlayerViewControllerAnimated:playerViewController]; 
    [playerViewController release]; 
    MPMoviePlayerController *player = [playerViewController moviePlayer]; 
    [player play]; 
}
+0

복잡한보기 계층 구조에서는 작동하지 않습니다. 이것을 확인하십시오 - http://stackoverflow.com/questions/3310909/mpmovieplayerviewcontroller-issue-after-movie-finishes/5738038#5738038 – Sid

0

저도 같은 문제가 있었과 나는이 해결이 workaroud을 사용했습니다 :

-(void)myMovieFinishedCallback:(NSNotification*)aNotification 
{ 
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     CGRect frame = CGRectMake(0, 20, 768, 1004); 
     self.view.frame = frame; 
    }else { 
     CGRect frame = CGRectMake(0, 20, 1004, 768); 
     self.view.frame = frame; 
    } 
} 

화면 크기로 Rect를 조정하면 내 코드가 iPad에서 작동합니다.

1

@Nuoji가 정답입니다. 해당 뷰의 프레임은 MPMoviePlayerViewController가 닫힐 때 iOS에 의해 애니메이션되고 있습니다. iOS의 버그로 인해 재생이 자동으로 종료 될 때 (동영상이 끝나는 시점) 애니메이션은 문제의보기가 전체 화면을 차지한다고 가정합니다.

단계 1. MPMoviePlayerViewController를 시작할보기가 포함 된 수퍼 뷰 프레임을 저장하십시오.

단계 2. 애니메이션을 완료 할 수 있도록 다시 원래뿐만 지연 후에 다시 프레임을 통지 처리기에서 playbackDidFinishNotification

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

단계 3. 청취자를 첨부. 애니메이션 중에 프레임이 수정되면 효과가 없습니다.

[self performSelector:@selector(resetFrame) 
      withObject:nil 
      afterDelay:kResetFrameDelay]; 

- (void)resetFrame { 
    self.view.frame = kApplicationFrame; 
} 
1

이 문제는 iOS 4.3 이상으로 해결되었으며 더 이상 문제되지 않습니다.

감사합니다.

관련 문제