0

このコードを追加しました:

[[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 になります。

編集:

これも毎回実装すると nil になります。

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

if ([reason intValue] == MPMoviePlaybackStateSeekingForward) {

    // done button clicked!

}
4

1 に答える 1

1

Problem is that you are adding notification for loadstate change of movie player and trying to access its playback state if you want playback state change notification you need to add observer for playback change notification

//for playback change

[[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;
}
}
于 2013-10-24T08:13:01.213 に答える