IOS WebAudio only works on headphones

前端 未结 4 2113
梦毁少年i
梦毁少年i 2020-12-14 05:22

I\'ve been running into an issue now for a while where on some ios devices my webaudio system only seems to work with headphones where as other devices (exact same os, model

4条回答
  •  情书的邮戳
    2020-12-14 06:09

    had same issue, and finally understood problem.

    indeed WebView don't play sound on internal speakers if phone is in mute.

    when i dig deeper i found a workaround :) original post => https://stackoverflow.com/a/37874619/8064246

    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        //print("AVAudioSession Category Playback OK")
        do {
            try AVAudioSession.sharedInstance().setActive(true)
            //print("AVAudioSession is Active")
        } catch _ as NSError {
            //print(error.localizedDescription)
        }
    } catch _ as NSError {
        //print(error.localizedDescription)
    }
    

提交回复
热议问题