2013-10-24 17 views
0
處理播放器按鈕

我加入這個代碼:在MPMoviePlayer

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadMoviePlayerStateChanged:) 
              name:MPMoviePlayerLoadStateDidChangeNotification 
              object:self.mp]; 

它激發我MPMoviePlayer的每一個狀態變化,這個功能:

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

    MPMoviePlayerController *Player = notification.object; 

    MPMoviePlaybackState playbackState = Player.playbackState; 
    if (playbackState == MPMoviePlaybackStateSeekingForward) 
    { 
     NSLog(@"Forward"); 
    } 
    else if (playbackState == MPMoviePlaybackStateSeekingBackward) 
    { 
     NSLog(@"Backward"); 
    } 
} 

進入此功能...

但問題是與MPMoviePlaybackState playbackState = Player.playbackState;

當我啓動玩家時,playerState爲1,其他所有更改都爲0. - 這怎麼可能?

編輯:

這也是每次執行給零:

NSNumber *reason = [notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey]; 

if ([reason intValue] == MPMoviePlaybackStateSeekingForward) { 

    // done button clicked! 

} 
+0

你想要加載狀態的電影播放器​​或播放狀態? –

回答

1

問題是,你的電影播放器​​的LoadState的變化增加的通知,並試圖如果你想訪問其播放狀態播放狀態更改通知您需要添加觀察者以播放更改通知

//用於播放更改

[[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playbackChanged) 
                name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.mp]; 




- (void)playbackChanged { 

switch ([self.mp playbackState]) { 
    case MPMoviePlaybackStateStopped: 
     NSLog(@"Stopped") 
     break; 
    case MPMoviePlaybackStatePlaying: 
     NSLog(@"Playing"); 
     break; 
    case MPMoviePlaybackStatePaused: 
     NSLog(@"Paused"); 
     break; 
    case MPMoviePlaybackStateInterrupted: 
     NSLog(@"Interrupted"); 
     break; 
    case MPMoviePlaybackStateSeekingForward: 
     NSLog(@"Seeking Forward"); 
     break; 
    case MPMoviePlaybackStateSeekingBackward: 
     NSLog(@"Seeking Backward"); 
     break; 
    default: 
     break; 
} 
}