0

ios, why webview load web with Phaser webaudio no sound when i mute the iphone or ipad ,my demo code like this

    override func viewDidLoad() {
        super.viewDidLoad()    
        view.addSubview(webView)
        let request = URLRequest(url: URL(string: "https://opas.firstleap.cn/web/game/1_1.1/index.html?pid=59149&&page=1")!) // this url is my app real url
        webView.load(request)
    }
    lazy fileprivate var webView: WKWebView = {
        let configuration = WKWebViewConfiguration()
          configuration.mediaPlaybackRequiresUserAction = false
        configuration.allowsInlineMediaPlayback = true
        let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height), configuration: configuration)
        webView.sizeToFit()
        webView.isOpaque = false //这个属性必须设置为false,否则在网络不好的情况下app推出后台,再次进来此页面会白屏
        webView.autoresizesSubviews = true
        webView.contentMode = .scaleToFill
        webView.scrollView.bounces = false
        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        webView.scrollView.contentSize = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
        return webView
      }()
James Skemp
  • 8,018
  • 9
  • 64
  • 107
romance
  • 15
  • 3
  • 1
    Welcome to StackOverflow. Please read [How to Ask](https://stackoverflow.com/help/how-to-ask). Be specific when you ask questions, showing your (related!) code, what the problem is, what you tried to fix it, what you got and what you expected instead. Also, the title might be misleading, because when I mute something, I would expect no sound as the valid response. – rkeet Jul 24 '17 at 09:59
  • Does this answer your question? [IOS WebAudio only works on headphones](https://stackoverflow.com/questions/21122418/ios-webaudio-only-works-on-headphones) – cigien Oct 29 '21 at 05:21
  • There is actually a solution to this. I answered an older question about it a few years ago and built a tiny library for it on github. I don't believe I have the privileges to mark questions as duplicate, but please see my answer here: https://stackoverflow.com/a/46839941/2103488 – Spencer Evans Oct 29 '21 at 05:09

1 Answers1

0

I encounter as the same issue as you, I use the HTML ,but abandon the webaudio to paly the sound.

xcq
  • 31
  • 1