iOS鎖屏音頻播放控制及音頻信息設(shè)置
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)文章
C語言素?cái)?shù)(質(zhì)數(shù))判斷的3種方法舉例
這篇文章主要給大家介紹了關(guān)于C語言素?cái)?shù)(質(zhì)數(shù))判斷的3種方法,質(zhì)數(shù)是只能被1或者自身整除的自然數(shù)(不包括1),稱為質(zhì)數(shù),文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11C語言全部內(nèi)存操作函數(shù)的實(shí)現(xiàn)詳細(xì)講解
這篇文章主要介紹了C語言全部內(nèi)存操作函數(shù)的實(shí)現(xiàn)詳細(xì)講解,作者用圖文代碼實(shí)例講解的很清晰,有感興趣的同學(xué)可以研究下2021-02-02C語言qsort函數(shù)用冒泡排序?qū)崿F(xiàn)過程詳解
qsort函數(shù)是由C語言提供的標(biāo)準(zhǔn)庫函數(shù), 它的實(shí)現(xiàn)思想是快速排序。這篇文章主要介紹了C語言中qsort函數(shù)用法及用冒泡排序?qū)崿F(xiàn)qsort函數(shù)功能,需要的可以參考一下2023-02-02用c語言實(shí)現(xiàn)《狼人殺》游戲發(fā)牌系統(tǒng)
大家好,本篇文章主要講的是用c語言實(shí)現(xiàn)《狼人殺》游戲發(fā)牌系統(tǒng),感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下2022-01-01VC6.0如何創(chuàng)建以及調(diào)用動(dòng)態(tài)鏈接庫實(shí)例詳解
作為客戶與后臺(tái)的中介,為了更好的調(diào)節(jié)兩方的關(guān)系,我明智滴選擇了webservice以及動(dòng)態(tài)鏈接庫。在與客戶c++使動(dòng)態(tài)鏈接庫方式,而與后臺(tái)java,使用webservice來交流溝通2013-01-01