WebView won't play any sound

前端 未结 2 1513
心在旅途
心在旅途 2021-01-04 13:06

I use the simplest instance of WebView and so far everything required works well, except for playing sounds, both javascript invoked sounds and html5 audio tag do not work t

相关标签:
2条回答
  • 2021-01-04 13:32

    I faced the same problem and searched a lot for playing audios in android WebViews. My audio files are stored in Google drive. I can play audio files stored in external servers other than Google drive easily using WebViews. But when I want to read it from Google drive, it shows the icon in the WebViews but when I play I get an error "The audio cannot be played". Finally I found a solution in the website https://www.labnol.org/internet/google-drive-mp3-embed/2232/ which is astonishing. He advises to change the last part of the url to 'preview'. For example the url will be of the form https://drive.google.com/file/d/1234ab56/view?usp=sharing, change the last part view?usp=sharing to preview. So finally url will be https://drive.google.com/file/d/1234ab56/preview. And now load it using the same code to load an embedded youtube video in WebView. Thank you.

    0 讨论(0)
  • 2021-01-04 13:50

    Try to add this

    webSettings.setMediaPlaybackRequiresUserGesture(false)
    
    0 讨论(0)
提交回复
热议问题