iOS中關(guān)于音樂鎖屏控制音樂(鎖屏信息設(shè)置)的實(shí)例代碼
廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:
<pre name="code" class="objc">appDelegate里面加入如下代碼獲取后臺(tái)播放權(quán)限</pre><pre name="code" class="objc">- (void)setAudioBackstagePlay{ AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil]; [audioSession setActive:YES error:nil]; }</pre> <pre></pre> <pre name="code" class="objc">//重寫父類方法,接受外部事件的處理 - (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent { NSLog(@"remote"); if (receivedEvent.type == UIEventTypeRemoteControl) { switch (receivedEvent.subtype) { // 得到事件類型 case UIEventSubtypeRemoteControlTogglePlayPause: // 暫停 ios6 [_player musicPause]; // 調(diào)用你所在項(xiàng)目的暫停按鈕的響應(yīng)方法 下面的也是如此 break; case UIEventSubtypeRemoteControlPreviousTrack: // 上一首 [self lastMusic]; break; case UIEventSubtypeRemoteControlNextTrack: // 下一首 [self nextMusic]; break; case UIEventSubtypeRemoteControlPlay: //播放 [_player musicPlay]; break; case UIEventSubtypeRemoteControlPause: // 暫停 ios7 [_player musicPause]; break; default: break; } } }</pre><pre name="code" class="objc"><pre name="code" class="objc">- (void)configNowPlayingCenter { NSLog(@"鎖屏設(shè)置"); // BASE_INFO_FUN(@"配置NowPlayingCenter"); YBVideoListModel * list = _model.audioList[_currentIndexPath.row];</pre><pre name="code" class="objc"><span style="white-space:pre"> </span>//以下代碼是加載鎖屏顯示網(wǎng)絡(luò)圖片以及其他設(shè)置 [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:list.thumbUrl] options:SDWebImageRetryFailed progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { if (image == nil) { image = [UIImage imageNamed:@"default_music"]; } NSMutableDictionary * info = [NSMutableDictionary dictionary]; //音樂的標(biāo)題 [info setObject:list.title forKey:MPMediaItemPropertyTitle]; //音樂的藝術(shù)家 NSString *author= list.singer; [info setObject:author forKey:MPMediaItemPropertyArtist]; //音樂的播放時(shí)間 [info setObject:@(_player.player.currentTime.value) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; //音樂的播放速度 [info setObject:@(1) forKey:MPNowPlayingInfoPropertyPlaybackRate]; //音樂的總時(shí)間 [info setObject:@(list.duration) forKey:MPMediaItemPropertyPlaybackDuration]; //音樂的封面 MPMediaItemArtwork * artwork = [[MPMediaItemArtwork alloc] initWithImage:image]; [info setObject:artwork forKey:MPMediaItemPropertyArtwork]; //完成設(shè)置 [[MPNowPlayingInfoCenter defaultCenter]setNowPlayingInfo:info]; }]; }</pre><br> <br> <pre></pre> <br> </pre>
以上所述是小編給大家介紹的 iOS中關(guān)于音樂鎖屏控制音樂(鎖屏信息設(shè)置)的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
iOS 斷點(diǎn)上傳文件的實(shí)現(xiàn)方法
這項(xiàng)目開發(fā)中,有時(shí)候我們需要將本地的文件上傳到服務(wù)器,簡單的幾張圖片還好,但是針對iPhone里面的視頻文件進(jìn)行上傳,為了用戶體驗(yàn),我們有必要實(shí)現(xiàn)斷點(diǎn)上傳。這篇文章主要介紹了iOS 斷點(diǎn)上傳文件的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-12-12詳解iOS App中UISwitch開關(guān)組件的基本創(chuàng)建及使用方法
UISwitch組件就是我們平時(shí)在iOS設(shè)置菜單中開到的那種左右滑動(dòng)的開關(guān)按鈕,當(dāng)然我們在開發(fā)時(shí)可以進(jìn)行更多的自定義,這里我們就來詳解iOS App中UISwitch開關(guān)組件的基本創(chuàng)建及使用方法2016-05-05iOS開發(fā)中UITabBarController的使用示例
這篇文章主要介紹了iOS開發(fā)中UITabBarController的使用示例,代碼基于Objective-C進(jìn)行演示,需要的朋友可以參考下2015-09-09IOS計(jì)步器功能實(shí)現(xiàn)之Healthkit和CMPedometer
現(xiàn)在越來越多的人關(guān)注運(yùn)動(dòng)和健康,iOS系統(tǒng)也在很早的時(shí)候就自帶了健康A(chǔ)PP,下面詳細(xì)描述一下在我們開發(fā)中,怎么實(shí)現(xiàn)計(jì)步器功能。2016-08-08使用iOS控件UICollectionView生成可拖動(dòng)的桌面的實(shí)例
本篇文章主要介紹了使用iOS控件UICollectionView生成可拖動(dòng)的桌面,具有一定的參考價(jià)值,有需要的可以了解一下。2016-12-12IOS開發(fā)之多線程N(yùn)SThiread GCD NSOperation Runloop
這篇文章主要介紹了IOS多線程開發(fā),主要用到NSThiread、GCD、 NSOperation、Runloop,有詳細(xì)的原理解析和實(shí)例代碼,對多線程感興趣的同學(xué),可以參考下2021-04-04