如何在remoteControlledEvents中选择下一首歌曲

时间:2012-07-19 17:49:01

标签: objective-c ios xcode avplayer

我正在使用AVPlayer我可以通过双击主页按钮或技术术语remoteControlledEvents来控制播放,暂停功能。我想知道如何实现它,以便我可以转到remoteControlledEvents的下一首曲目。

谢谢

-(void)remoteControlReceivedWithEvent:(UIEvent *)event {
  switch (event.subtype) {
    case UIEventSubtypeRemoteControlTogglePlayPause:
      if (avplayer.rate == 0.0) {
        [avplayer play];
      } else {
        [avplayer pause];
      }
      break;
    case UIEventSubtypeRemoteControlPlay:
      [avplayer play];
      break;
    case UIEventSubtypeRemoteControlPause:
      [avplayer pause];
      break;

  }
}

1 个答案:

答案 0 :(得分:1)

使用下一首歌创建一个新AVPlayer并告诉它播放。

活动为UIEventSubtypeRemoteControlNextTrack

case: UIEventSubtypeRemoteControlNextTrack:
    [avplayer pause];
    avplayer = [[AVPlayer alloc] initWithPlayerItem:/*name of item*/];
    [avplayer play];
    break;