How to solve “NotAllowedError: play() can only be initiated by a user gesture.” audio problem in javascript android webview?
- Thursday, December 20, 2018, 15:14
- Android, How-to, Javascript
- 2 comments
While playing audio in javascript using webview in android platform we may encounter following problem NotAllowedError: play() can only be initiated by a user gesture.. This is due to security and good user experience issue. So to enable sound play we should use following code in android:
1 2 3 4 |
int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT > 16) { WebViewWithJavaScript.getSettings().setMediaPlaybackRequiresUserGesture(false); } |
Android SDK below 17 will not support this hack so we should use the condition.
Please comment if this worked for you. Thanks.
About the Author
2 Comments on “How to solve “NotAllowedError: play() can only be initiated by a user gesture.” audio problem in javascript android webview?”
Write a Comment
Gravatars are small images that can show your personality. You can get your gravatar for free today!
Tx for explanation.
I occurre same problem
Works for me, thanks 🙂