{"id":221,"date":"2018-12-20T15:14:12","date_gmt":"2018-12-20T15:14:12","guid":{"rendered":"http:\/\/rat32.com\/rat32\/?p=221"},"modified":"2018-12-20T15:14:12","modified_gmt":"2018-12-20T15:14:12","slug":"how-to-solve-notallowederror-play-can-only-be-initiated-by-a-user-gesture-audio-problem-in-javascript-android-webview","status":"publish","type":"post","link":"https:\/\/rat32.com\/rat32\/2018\/12\/20\/how-to-solve-notallowederror-play-can-only-be-initiated-by-a-user-gesture-audio-problem-in-javascript-android-webview\/","title":{"rendered":"How to solve &#8220;NotAllowedError: play() can only be initiated by a user gesture.&#8221; audio problem in javascript android webview?"},"content":{"rendered":"<p>While playing audio in javascript using webview in android platform we may encounter following problem <strong><em>NotAllowedError: play() can only be initiated by a user gesture.<\/em><\/strong>. This is due to security and good user experience issue. So to enable sound play we should use following code in android:<\/p>\n<pre class=\"lang:java decode:true \" >int SDK_INT = android.os.Build.VERSION.SDK_INT;\r\nif (SDK_INT &gt; 16) {\r\n    WebViewWithJavaScript.getSettings().setMediaPlaybackRequiresUserGesture(false);\r\n}<\/pre>\n<p>Android SDK below 17 will not support this hack so we should use the condition.<\/p>\n<p>Please comment if this worked for you. Thanks.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>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&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,7,45],"tags":[142,150,151,63,149],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-android","category-how-to","category-javascript","tag-android","tag-audio","tag-html","tag-javascript-2","tag-webview"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts\/221"}],"collection":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":1,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":222,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/posts\/221\/revisions\/222"}],"wp:attachment":[{"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rat32.com\/rat32\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}