簡體   English   中英

如何關閉MPMoviePlayer? 正確地從一個ViewController到另一個

[英]how to dismiss MPMoviePlayer ? properly from one ViewController to another

我正在使用通知中心來接收MPMoviePlayerPlaybackDidFinishNotification,它可以按預期工作。

   NSURL * url = [[NSURL alloc] initWithString:@"http://INFINITECREATIVEUNIVERSE.COM/Media/module_1_Dec/c_January27AffactPerfect.mov"];

    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

    [moviePlayer.view setFrame:CGRectMake(0, 0, 500, 260)];

    [self.view addSubview:moviePlayer.view];

    //Some addiontal customization
    moviePlayer.fullscreen = YES;
    moviePlayer.allowsAirPlay = YES;
    moviePlayer.shouldAutoplay = YES;
    moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    //moviePlayer.endPlaybackTime = NO;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playMovieFinished:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];

選擇器會執行我想要的操作。

-(void)playMovieFinished:(NSNotification*)theNotification
{
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:moviePlayer];
    //                     Change Segue ID Here    

    [self  performSegueWithIdentifier:@"VC_5" sender:self];
}

當我仍在播放視頻時,單擊下一步按鈕會出現我的問題。 當我的下一個ViewController出現時,沒有視頻,我仍然可以聽到前一個ViewController的音頻。

我的問題是:如何正確解雇視圖控制器和MPMoviePlayer。 我搞不清楚了。 我從Apple下載了示例MoviePlayer項目,但現在已棄用該項目,並且該項目無法正常工作。 我迷失了如何使這項工作。 我用手指交叉問了正確的問題。 請憐憫我的新手問題。 謝謝羅伯特

使用此代碼

-(void)playMovieFinished:(NSNotification*)theNotification
{
    [[NSNotificationCenter defaultCenter]
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:moviePlayer];
    [moviePlayer stop];
    // Change Segue ID Here    

    [self  performSegueWithIdentifier:@"VC_5" sender:self];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM