【问题标题】:MPMoviePlayerController next previous buttons incorrect notificationsMPMoviePlayerController 下一个上一个按钮不正确的通知
【发布时间】:2015-05-12 14:40:56
【问题描述】:

我有MPMoviePlayerController,我只想检测下一个/上一个按钮以便相应地播放播放列表,我添加了通知,但它总是返回MPMoviePlaybackStateStopped 状态而不是MPMoviePlaybackStateSeekingForwardMPMoviePlaybackStateSeekingBackward

代码如下:

[[NSNotificationCenter defaultCenter] addObserver:self // the object listening / "observing" to the notification
                                         selector:@selector(stateChanged:) // method to call when the notification was pushed
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification // notification the observer should listen to
                                           object:nil];

并在回调函数中:

-(void)stateChanged:(NSNotification *)notification{
MPMoviePlaybackState state = self.moviePlayerViewController.moviePlayer.playbackState;
switch (state) {
    case MPMoviePlaybackStateStopped:
        NSLog(@"Stopped");
        break;
    case MPMoviePlaybackStateInterrupted:
        NSLog(@"Interrupted");
        break;
    case MPMoviePlaybackStateSeekingForward:
        NSLog(@"forward");
        currentIndex++;
        ForcePlay = true;
        [self PlayVideo:currentIndex];
        break;
    case MPMoviePlaybackStateSeekingBackward:
        NSLog(@"backward");
        currentIndex--;
        ForcePlay = true;
        [self PlayVideo:currentIndex];
        break;
    case MPMoviePlaybackStatePaused:
        NSLog(@"paused");
        break;
    case MPMoviePlaybackStatePlaying:
        NSLog(@"playing");
        break;
}
}

【问题讨论】:

    标签: ios mpmovieplayercontroller nsnotifications


    【解决方案1】:

    MPMoviePlayerController 的默认控件只有基本功能。点击 Prev/Next 只会调用一个状态,即MPMoviePlaybackStateStopped

    如果您希望能够检测上一个/下一个,您必须实现自己的自定义控件,并通过使用 MPMovieControlStyleNone 隐藏默认控件来单独对每个按钮执行操作

    例如在 Obj-C 中:

    [prevBtn addTarget:self action:@selector(onClick:) 
    forControlEvents:UIControlEventTouchUpInside];
    
    [nextBtn addTarget:self action:@selector(onClick:) 
    forControlEvents:UIControlEventTouchUpInside];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-20
      相关资源
      最近更新 更多