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)文章
淺談Windows系統(tǒng)下C語言編程中Glib庫的使用
這篇文章主要介紹了Windows系統(tǒng)下C語言編程中Glib庫的使用,Glib庫在多線程編程中經(jīng)??梢杂玫?需要的朋友可以參考下2016-02-02
C++求1到n中1出現(xiàn)的次數(shù)以及數(shù)的二進(jìn)制表示中1的個(gè)數(shù)
這篇文章主要介紹了C++求1到n中1出現(xiàn)的次數(shù)以及數(shù)的二進(jìn)制表示中1的個(gè)數(shù),兩道基礎(chǔ)的算法題目,文中也給出了解題思路,需要的朋友可以參考下2016-02-02
一篇文章帶你了解C語言內(nèi)存對(duì)齊解決的問題
內(nèi)存對(duì)齊的目的是為了提高CPU讀寫內(nèi)存里數(shù)據(jù)的速度?,F(xiàn)代的CPU讀取內(nèi)存并不是一個(gè)一個(gè)字節(jié)挨著讀取,這樣做的效率非常低。現(xiàn)代的CPU一般以4個(gè)字節(jié)(32bit數(shù)據(jù)總線)或者8個(gè)字節(jié)(64bit數(shù)據(jù)總線)為一組,一組一組地讀寫內(nèi)存里的數(shù)據(jù)2021-08-08
C++實(shí)現(xiàn)LeetCode(104.二叉樹的最大深度)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(104.二叉樹的最大深度),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07

