How to choose next song in remoteControlledEvents

二次信任 提交于 2020-01-06 02:58:26

问题


I am using AVPlayer where I can control play, pause function by double tapping home button or in technical terms remoteControlledEvents. I was wondering how to implement it so I can go to the next track in remoteControlledEvents.

Thanks

-(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:


Make a new AVPlayer with the next song and tell it to play.

The event is UIEventSubtypeRemoteControlNextTrack

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


来源:https://stackoverflow.com/questions/11566512/how-to-choose-next-song-in-remotecontrolledevents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!