第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何讓音效在應(yīng)用處于后臺(tái)狀態(tài)時(shí)自動(dòng)停止

如何讓音效在應(yīng)用處于后臺(tái)狀態(tài)時(shí)自動(dòng)停止

DIEA 2019-04-21 20:40:05
我現(xiàn)在在用AVAduioPlayer在后臺(tái)播放音效(白噪音軟件),然后應(yīng)用是允許用戶設(shè)置播放時(shí)間的,但是當(dāng)應(yīng)用在后臺(tái)時(shí),NSTimer的回調(diào)函數(shù)是不會(huì)被調(diào)用的,這個(gè)時(shí)候我該如何停止音效呢?代碼:-(void)play:(NSString*)soundNamewithTime:(NSNumber*)time{NSURL*soundUrl=[NSURLfileURLWithPath:[NSStringstringWithFormat:@"%@/sounds/%@.m4a",[[NSBundlemainBundle]resourcePath],soundName]];_audioPlayer=[[AVAudioPlayeralloc]initWithContentsOfURL:soundUrlerror:nil];_audioPlayer.numberOfLoops=-1;[_audioPlayerplay];[[AVAudioSessionsharedInstance]setCategory:AVAudioSessionCategoryPlaybackerror:nil];[[AVAudioSessionsharedInstance]setActive:YESerror:nil];[selfscheduleStopSound:time];//howtoimplementit.}
查看完整描述

2 回答

?
呼如林

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊

以下是解決辦法:
objectivec//App將要進(jìn)入后臺(tái),實(shí)現(xiàn)applicationDidEnterBackgroundNotification,做處理
[NSNotificationCenter.defaultCenteraddObserver:selfselector:@selector(applicationDidEnterBackgroundNotification)name:UIApplicationDidEnterBackgroundNotificationobject:nil];
//App將要回到前臺(tái),實(shí)現(xiàn)applicationWillEnterForegroundNotification,做處理
[NSNotificationCenter.defaultCenteraddObserver:selfselector:@selector(applicationWillEnterForegroundNotification)name:UIApplicationWillEnterForegroundNotificationobject:nil];
你還可以在AppDelegate里面實(shí)現(xiàn)對應(yīng)的方法來做處理,但是不建議你這么做,因?yàn)檫@樣會(huì)讓AppDelegate里面堆積太多要處理的東西,通過系統(tǒng)通知進(jìn)行處理的好處是可以把這些耦合解開。
                            
查看完整回答
反對 回復(fù) 2019-04-21
?
翻過高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊

我印象中可以直接配置出這個(gè)效果吧。
試試[[AVAudioSessionsharedInstance]setCategory:AVAudioSessionCategorySoloAmbienterror:nil];,看可以嗎?
                            
查看完整回答
反對 回復(fù) 2019-04-21
  • 2 回答
  • 0 關(guān)注
  • 280 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)