這篇文章將為大家詳細(xì)講解有關(guān)iOS中音樂鎖屏控制音樂的示例分析,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
具體代碼如下所示:
<pre name="code" class="objc">appDelegate里面加入如下代碼獲取后臺播放權(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)用你所在項目的暫停按鈕的響應(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 > </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]; //音樂的播放時間 [info setObject:@(_player.player.currentTime.value) forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime]; //音樂的播放速度 [info setObject:@(1) forKey:MPNowPlayingInfoPropertyPlaybackRate]; //音樂的總時間 [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>
關(guān)于“iOS中音樂鎖屏控制音樂的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站chinadenli.net,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
本文名稱:iOS中音樂鎖屏控制音樂的示例分析-創(chuàng)新互聯(lián)
本文來源:http://chinadenli.net/article18/iddgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、網(wǎng)站設(shè)計公司、云服務(wù)器、定制開發(fā)、外貿(mào)網(wǎng)站建設(shè)、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容