2017-08-04 141 views
0

我正在製作音樂應用程序。iOS支持從其他音樂應用程序返回後播放音頻

這裏是我想修復的情況: 我打開AppleMusic應用程序>玩東西>打開我的應用程序>點擊播放>音樂不播放。爲什麼以及如何解決它?

我用,但仍然無法正常工作

func applicationDidBecomeActive(_ application: UIApplication) { 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    do { 
     try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) 
     try AVAudioSession.sharedInstance().setActive(true) 
    } catch let error as NSError { 
     print(error.localizedDescription) 
    } 
    UIApplication.shared.beginReceivingRemoteControlEvents() 
} 

回答

0

此代碼顯示,如果另一個應用是在研究背景

var otherAudioPlaying = AVAudioSession.sharedInstance().isOtherAudioPlaying 

如果是播放聲音,試試這個:

AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil) 
相關問題