1

MPMoviePlayerViewControllerをフル スクリーン モードで表示したいのですが、movieplayercontroller ビューのフルスクリーン ボタンが押されたときに、予想どおり、最初にMPMoviePlayerWillEnterFullscreenNotificationが呼び出されますが、MPMoviePlayerPlaybackDidFinishNotificationも送信されます。理由としてMPMovieFinishReasonPlaybackEndedと表示されていますが、何が間違っているのかわかりません。(さらに、私はiOS 6.0XCode 4.5.1を使用します)

私の期待は、MPMoviePlayerWillEnterFullscreenNotificationだけが呼び出されているということです。

以下のコードの簡単な説明: MovieplayerViewController のビューは、コンテンツ ビューの小さなサブビューに表示されています。フルスクリーン ボタンをタップすると、最初にフルスクリーンとして表示されますが、終了ボタンも呼び出されて再生が停止します (クラッシュは発生しません)。

MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

   [playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];

   [playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];

   CGRect rect = videoView.frame;

   rect.origin = CGPointZero;

   [playerViewController.view setFrame:rect];

   [playerViewController.moviePlayer prepareToPlay];


        //movie this is my contents subview, where i add the viewcontroller's view as a subbview
    [self.videoView addSubview:playerViewController.view];

    [self.videoView setHidden:NO];


    playerViewController.moviePlayer.useApplicationAudioSession = NO;

    [playerViewController.moviePlayer play];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerDidFinishNotification:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:playerViewController.moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillEnterFullscreenNotification:)
                                                 name:MPMoviePlayerWillEnterFullscreenNotification
                                               object:playerViewController.moviePlayer];    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerWillExitFullscreenNotification:)
                                                 name:MPMoviePlayerWillExitFullscreenNotification
                                               object:playerViewController.moviePlayer];

        //i store the movieplayer in a property, so i can use it for further operations
    self.myPlayer = playerViewController;

    [playerViewController release];

以上です!

サイズ変更 (またはフルスクリーン) ボタンが押されると、moviePlayerDidFinishNotification: メソッドも呼び出されます。

- (void)moviePlayerDidFinishNotification:(NSNotification*) aNotification {

    int reason = [[[aNotification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];

    if (reason == MPMovieFinishReasonPlaybackEnded) {

        //movie finished playin

//in debug mode, it stops right at the NSLog

        NSLog(@"");
    }

    else if (reason == MPMovieFinishReasonUserExited) {

        //user hit the done button

    }

    else if (reason == MPMovieFinishReasonPlaybackError) {

        //error

    }

.. }

何か間違っているのでしょうか、それとも iOS 6.0 から変更されたのでしょうか?

4

2 に答える 2

0

OK、MPMoviePlayerViewController に問題があるようです。助けになったのは、MPMoviePlayerController のみを単純にすることです。

于 2012-10-23T07:30:39.553 に答える
0

今後の参考のために、プレーヤーが小さなウィンドウに表示された理由は、次のように設定していたためです。

 [playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];

   [playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];

   CGRect rect = videoView.frame;

   rect.origin = CGPointZero;

   [playerViewController.view setFrame:rect];

   [playerViewController.moviePlayer prepareToPlay];


        //movie this is my contents subview, where i add the viewcontroller's view as a subbview
    [self.videoView addSubview:playerViewController.view];

    [self.videoView setHidden:NO];

MPMoviePlayerViewController を使用すると、独自のビュー コントローラーが作成されます。これらの呼び出しは必要ではなく、奇妙な動作を引き起こすだけです。そのため、MPMoviePlayerController は別のビュー コントローラー内で動作するように設計されているため、適切に動作しました。

于 2013-02-07T13:32:15.940 に答える