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

好的,似乎是 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];

When you use an MPMoviePlayerViewController it creates it's own view controller. These calls are not necessary and will only create bizarre behavior. That's why the MPMoviePlayerController worked properly because it's designed to work inside another view controller.

于 2013-02-07T13:32:15.940 回答