国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ios播放聲音中斷后臺音樂的問題

2019-11-14 19:03:42
字體:
來源:轉載
供稿:網友
 

 今天遇到一個ios播放聲音中斷后臺音樂的問題,在我的app中如果調用AVAudiosession 播放完聲音,后臺的QQ音樂偶爾不能恢復,而網易云音樂一次都不能恢復播放,研究了一下AVAudioSession ,我之前調用[audioSession setActive:NO error:&err];還有一個方法

/* Set the session active or inactive. Note that activating an audio session is a synchronous (blocking) Operation.

 Therefore, we recommend that applications not activate their session from a thread where a long blocking operation will be PRoblematic.

 Note that this method will throw an exception in apps linked on or after iOS 8 if the session is set inactive while it has running or 

 paused I/O (e.g. audio queues, players, recorders, converters, remote I/Os, etc.).

*/

- (BOOL)setActive:(BOOL)active error:(NSError **)outError;

- (BOOL)setActive:(BOOL)active withOptions:(AVAudioSessionSetActiveOptions)options error:(NSError **)outError NS_AVAILABLE_IOS(6_0);

而AVAudioSessionSetActiveOptions這個枚舉

/*  options for use when calling setActive:withOptions:error: 

AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation -- 

Notify an interrupted app that the interruption has ended and it may resume playback. Only valid on 

session deactivation. */

typedef NS_OPTIONS(NSUInteger, AVAudioSessionSetActiveOptions)

{

AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation = 1

} NS_AVAILABLE_IOS(6_0);

注釋的意思是:“通知中斷程序中斷已經結束,可以恢復播放。。。。“,

看來這里應該是造成播放聲音導致后臺的qq音樂偶爾不能恢復,而網易云音樂一次都不能恢復播放的地方

 

 之后改成調用   [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];果然網易云音樂也可以恢復了,看了蘋果官方的文章,上面有張圖

 

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新巴尔虎右旗| 绩溪县| 东宁县| 大连市| 明水县| 昆山市| 会宁县| 凤凰县| 景宁| 静乐县| 石台县| 南充市| 广宗县| 玉树县| 荆州市| 石首市| 建水县| 迭部县| 石阡县| 芜湖县| 含山县| 隆子县| 武冈市| 抚顺市| 卢龙县| 潜山县| 东兴市| 鹤庆县| 玛曲县| 阿坝县| 玛沁县| 神农架林区| 镇坪县| 开封市| 宁化县| 石泉县| 勃利县| 新建县| 鹤壁市| 随州市| 仁化县|