美文网首页
播放器后台播放

播放器后台播放

作者: 海是天空蓝 | 来源:发表于2022-11-29 15:16 被阅读0次
    • (void) viewWillAppear:(BOOL)animated
      {
      [super viewWillAppear:animated];
      [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
      [self becomeFirstResponder];
      }

    • (void) viewWillDisappear:(BOOL)animated
      {
      [super viewWillDisappear:animated];
      [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
      [self resignFirstResponder];
      }

    pragma mark - Player Controll

    • (void)remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
      NSMutableDictionary * info = [NSMutableDictionary dictionary];
      //音乐的标题
      [info setObject:@"leao" forKey:MPMediaItemPropertyTitle];
      //音乐的艺术家
      [info setObject:@"chocolate" forKey:MPMediaItemPropertyArtist];
      //音乐的播放时间
      [info setObject:@(self.audioPlayer.duration) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
      //音乐的播放速度
      [info setObject:@(1) forKey:MPNowPlayingInfoPropertyPlaybackRate];
      //音乐的总时间
      [info setObject:@(self.audioPlayer.duration) forKey:MPMediaItemPropertyPlaybackDuration];
      //音乐的封面
      MPMediaItemArtwork * artwork = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"main_icon_review"]];
      [info setObject:artwork forKey:MPMediaItemPropertyArtwork];
      //完成设置
      [[MPNowPlayingInfoCenter defaultCenter]setNowPlayingInfo:info];

      if (receivedEvent.type == UIEventTypeRemoteControl) {

        switch (receivedEvent.subtype) {
      
            case UIEventSubtypeRemoteControlTogglePlayPause:
      
                break;
      
            case UIEventSubtypeRemoteControlPreviousTrack:
      
                break;
      
            case UIEventSubtypeRemoteControlNextTrack:
      
                break;
      
            default:
                break;
        }
      

      }
      }

    相关文章

      网友评论

          本文标题:播放器后台播放

          本文链接:https://www.haomeiwen.com/subject/cacpwrtx.html