2011-07-07 110 views
0

我正在嘗試構建帶有功能的後退按鈕,點擊該按鈕時應停止播放的視頻。 在我的情況下,它從超視圖中刪除,但視頻仍在後臺播放。 我做如下,但它不工作iphone:如何停止點擊「後退」按鈕播放視頻?

-(IBAction)backButtonPressed 
     { 
      [[NSNotificationCenter defaultCenter] addObserver:self   selector:@selector(movieDidExitFullScreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; 
      [self.navigationController popViewControllerAnimated:YES]; 
     } 

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

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

    MPMoviePlayerController *theMovie1 = [notification object]; 

    [self.navigationController popViewControllerAnimated:YES]; 

    [theMovie1 release]; 
} 

回答

0

替換後退按鈕動作事件的下方。

-(IBAction)backButtonPressed 
{ 
    [player stop]; 
    [player release]; 
    player =nil; 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

這會停止播放器並在返回之前釋放它。希望這個幫助。

0

實際上,您並沒有停止播放該代碼中的電影,而只是刪除了顯示該視頻的視圖。您在視頻停止時設置通知,以便movieDidExitFullScreen方法不會被調用,直到視頻完成播放。最簡單的解決方案是致電[theMovie1 stop],但您需要以某種方式訪問​​您的電影backButtonPressed

相關問題