欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS鎖屏音頻播放控制及音頻信息設(shè)置

 更新時(shí)間:2019年12月23日 09:47:17   作者:hero_wqb  
這篇文章主要為大家詳細(xì)介紹了iOS鎖屏音頻播放控制及音頻信息設(shè)置,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

iOS 后臺(tái)音頻播放控制,鎖屏音頻播放控制及音頻信息設(shè)置,效果圖如下:

 

1.在 AppDelegate.m 中實(shí)現(xiàn)下面方法,獲取音頻播放、暫停、上一首、下一首點(diǎn)擊事件:

- (BOOL)canBecomeFirstResponder
{
 return YES;
}
 
//鎖屏界面控制監(jiān)聽
- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
 if (event.type == UIEventTypeRemoteControl) {
  switch (event.subtype) {
   case UIEventSubtypeRemoteControlPlay:
   {
    //播放
    NSLog(@"Play");
    break;
   }
   case UIEventSubtypeRemoteControlPause:
   {
    //暫停
    NSLog(@"Pause");
    break;
   }
   case UIEventSubtypeRemoteControlNextTrack:
   {
    //下一首
    NSLog(@"Next");
    break;
   }
   case UIEventSubtypeRemoteControlPreviousTrack:
   {
    //上一首
    NSLog(@"Previous");
    break;
   }
   default:
    break;
  }
 }
}

2.設(shè)置鎖屏信息:

//設(shè)置鎖屏信息
- (void)setLockingInfo
{
 Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
 
 if (playingInfoCenter) {
  //音頻模型
  HWMusicModel *model = [HWMusicTool playingMusic];
  
  //數(shù)據(jù)信息
  NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  
  //圖片
  MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageWithUrlString:model.icon]];
  [songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
  
  //當(dāng)前播放時(shí)間
  [songInfo setObject:[NSNumber numberWithDouble:[[[HWMusicTool shareMusicTool] Player] currentPlaybackTime]] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
  //速率
  [songInfo setObject:[NSNumber numberWithFloat:1.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
  //剩余時(shí)長
  [songInfo setObject:[NSNumber numberWithDouble:[[[HWMusicTool shareMusicTool] Player] duration]] forKey:MPMediaItemPropertyPlaybackDuration];
  
  //設(shè)置標(biāo)題
  [songInfo setObject:model.title forKey:MPMediaItemPropertyTitle];
  
  //設(shè)置副標(biāo)題
  [songInfo setObject:@"周杰倫 - 周杰倫的床邊故事" forKey:MPMediaItemPropertyArtist];
  
  //設(shè)置音頻數(shù)據(jù)信息
  [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
 }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論