2012-03-05 6 views
7

私はMPMoviePlayerControllerオブジェクトを作成し、フルスクリーンモードでビデオをストリーミングしています。MPMoviePlayerControllerは、クリックしたときにビューを削除しません。

私はムービービューを表示するためにUIViewControllerを使用しています。

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    //http://www.youtube.com/watch?feature=player_detailpage&v=ebeQaznNcmE 
    NSURL *url = [NSURL URLWithString:@"http://a1408.g.akamai.net/5/1408/1388/2005110405/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_mpeg4.mp4"]; 
    MPMoviePlayerController *mPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url]; 
    mPlayer.view.frame = gMainView.frame; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayBackDidFinish:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:mPlayer]; 
    mPlayer.shouldAutoplay = YES; 
    mPlayer.controlStyle = MPMovieControlStyleFullscreen; 
    [gMainView addSubview:mPlayer.view]; 
    [mPlayer prepareToPlay]; 
    [mPlayer setFullscreen:YES animated:YES]; 
    [mPlayer play]; 
} 


- (void)moviePlayBackDidFinish:(NSNotification*)notification { 
    int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; 
    if (reason == MPMovieFinishReasonPlaybackEnded) { 
     //movie finished playing 
    } 
    else if (reason == MPMovieFinishReasonUserExited) { 
     //user hit the done button 
     MPMoviePlayerController *moviePlayer = [notification object]; 

     [[NSNotificationCenter defaultCenter] removeObserver:self  
                 name:MPMoviePlayerPlaybackDidFinishNotification 
                 object:moviePlayer]; 

     if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) { 
      [moviePlayer.view removeFromSuperview]; 
     } 
     [moviePlayer release]; 
    } 
    else if (reason == MPMovieFinishReasonPlaybackError) { 
     //error 
    } 
} 

ビデオビジュアルは画面から削除されますが、コントロールは画面から削除されず、画面から削除されません。

コントロールは「//ユーザが完了ボタンを押した」になります。スーパービューからビューを削除するコードを実行し、ログを追加してチェックしました()、コントロールは画面から削除されず、ビューは画面から削除されません。 私は何が間違っていますか?

EDIT:

私はMPMoviePlayerViewControllerを使用している場合は、私が完了を押すようにするために、それも待ちません。ビデオが完成すると、自動的にビューが削除されます。しかし、私はそれを望んでいません。

EDIT:

私が削除した場合、 "[MPlayerのsetFullscreen:YESアニメーション:YES]" Doneをクリックすると、その後、ビューが完全に除去されます。しかし、ビデオはフルスクリーンで表示されず、ステータスバーはグレーになります。これは私が望まないものです。

+0

あなたはしたくないけど、少なくとも私には、これはまだ本当にあなたが実際に達成したいものを述べるいないかを説明するために多くの措置をとります。 – Till

+0

コントロールが画面から削除されず、プレーヤーの表示が画面から削除されません。 – Anand

+1

このソリューションをお試しください:http://stackoverflow.com/questions/6142571/mpmovieplayer-done-button-issue/6142685#6142685 – Till

答えて

10

以下のコードは私のために働いてくれました。

-(IBAction)playVedio:(id)sender{ 
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 

    [[mp moviePlayer] prepareToPlay]; 
    [[mp moviePlayer] setUseApplicationAudioSession:NO]; 
    [[mp moviePlayer] setShouldAutoplay:YES]; 
    [[mp moviePlayer] setControlStyle:2]; 
    [[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 
    [self presentMoviePlayerViewControllerAnimated:mp]; 

} 

-(void)videoPlayBackDidFinish:(NSNotification*)notification { 

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 

    [mp.moviePlayer stop]; 
    mp = nil; 
    [mp release]; 
    [self dismissMoviePlayerViewControllerAnimated]; 
} 
+0

また、Sirjiは、他の人が簡単にあなたの答えを理解できるコードを何か追加してください。コードで問題が何だったのか質問を解決するために何をしましたか? ) – MKJParekh

+0

vlは次回に注意してください!! !! :) – Sirji

+4

あなたは大声で票を偽造するべきではありません。 – Till

0
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    id presentedViewController = [window.rootViewController presentedViewController]; 
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil; 

    if (window && [className isEqualToString:@"AVFullScreenViewController"]) { 

     return UIInterfaceOrientationMaskAll; 

    } else { 

     UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; 

     if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) 

     { 

     } 

     else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) 

     { 


     } 

     return UIInterfaceOrientationMaskPortrait; 

     CGRect frame = [UIScreen mainScreen].applicationFrame; 
     CGSize size = frame.size; 
     NSLog(@"%@", [NSString stringWithFormat:@"Rotation: %s [w=%f, h=%f]", 
         UIInterfaceOrientationIsPortrait(interfaceOrientation) ? "Portrait" : "Landscape", 
         size.width, size.height]); 
    } 
} 
関連する問題