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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何讓音效在應用處于后臺狀態(tài)時自動停止

如何讓音效在應用處于后臺狀態(tài)時自動停止

開滿天機 2019-04-23 15:12:49
我現(xiàn)在在用AVAduioPlayer在后臺播放音效(白噪音軟件),然后應用是允許用戶設置播放時間的,但是當應用在后臺時,NSTimer的回調(diào)函數(shù)是不會被調(diào)用的,這個時候我該如何停止音效呢?代碼:-(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貢獻1806條經(jīng)驗 獲得超8個贊

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

TA貢獻1824條經(jīng)驗 獲得超8個贊

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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號