iOS鎖屏音頻播放控制及音頻信息設置
更新時間:2019年12月23日 09:47:17 作者:hero_wqb
這篇文章主要為大家詳細介紹了iOS鎖屏音頻播放控制及音頻信息設置,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
iOS 后臺音頻播放控制,鎖屏音頻播放控制及音頻信息設置,效果圖如下:
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.設置鎖屏信息:
//設置鎖屏信息 - (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]; //設置標題 [songInfo setObject:model.title forKey:MPMediaItemPropertyTitle]; //設置副標題 [songInfo setObject:@"周杰倫 - 周杰倫的床邊故事" forKey:MPMediaItemPropertyArtist]; //設置音頻數(shù)據(jù)信息 [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo]; } }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C語言qsort函數(shù)用冒泡排序實現(xiàn)過程詳解
qsort函數(shù)是由C語言提供的標準庫函數(shù), 它的實現(xiàn)思想是快速排序。這篇文章主要介紹了C語言中qsort函數(shù)用法及用冒泡排序實現(xiàn)qsort函數(shù)功能,需要的可以參考一下2023-02-02用c語言實現(xiàn)《狼人殺》游戲發(fā)牌系統(tǒng)
大家好,本篇文章主要講的是用c語言實現(xiàn)《狼人殺》游戲發(fā)牌系統(tǒng),感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下2022-01-01VC6.0如何創(chuàng)建以及調用動態(tài)鏈接庫實例詳解
作為客戶與后臺的中介,為了更好的調節(jié)兩方的關系,我明智滴選擇了webservice以及動態(tài)鏈接庫。在與客戶c++使動態(tài)鏈接庫方式,而與后臺java,使用webservice來交流溝通2013-01-01