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

這篇文章將為大家詳細講解有關(guān)iOS中鎖屏音頻播放控制及音頻信息如何設(shè)置,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)主要從事網(wǎng)站設(shè)計、做網(wǎng)站、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務吉安,10余年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18980820575

效果圖如下:

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

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

1.在 AppDelegate.m 中實現(xià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];
  
  //當前播放時間
  [songInfo setObject:[NSNumber numberWithDouble:[[[HWMusicTool shareMusicTool] Player] currentPlaybackTime]] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
  //速率
  [songInfo setObject:[NSNumber numberWithFloat:1.0f] forKey:MPNowPlayingInfoPropertyPlaybackRate];
  //剩余時長
  [songInfo setObject:[NSNumber numberWithDouble:[[[HWMusicTool shareMusicTool] Player] duration]] forKey:MPMediaItemPropertyPlaybackDuration];
  
  //設(shè)置標題
  [songInfo setObject:model.title forKey:MPMediaItemPropertyTitle];
  
  //設(shè)置副標題
  [songInfo setObject:@"周杰倫 - 周杰倫的床邊故事" forKey:MPMediaItemPropertyArtist];
  
  //設(shè)置音頻數(shù)據(jù)信息
  [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
 }
}

關(guān)于“iOS中鎖屏音頻播放控制及音頻信息如何設(shè)置”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

網(wǎng)站名稱:iOS中鎖屏音頻播放控制及音頻信息如何設(shè)置
網(wǎng)頁URL:http://muchs.cn/article32/pdpesc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站營銷關(guān)鍵詞優(yōu)化、做網(wǎng)站、品牌網(wǎng)站設(shè)計、微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設(shè)