jay
jay

Reputation: 2032

Android webView - autoplay youtube video from URL

Struggling to achieve Youtube Video Auto play within android WebView, I have seen several threads and forums listing following suggestion which DO NOT WORK.

I have tried the following, with no luck:

  1. settings.setMediaPlaybackRequiresUserGesture(false);

  2. Adding javascript snip like this:

    webView.setWebViewClient(new MyWebViewClient(){
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (view.getProgress() == 100) {
                webView.loadUrl("javascript:document.getElementsByTagName('video')[0].play();"
                );
            }
        }
    });
    

3 . Adding &autoplay=1 to URL

I am tested for all the above methods in API 18 and none of the above methods worked. This being a very important Feature for my App, please provide a working solution for this.

Upvotes: 1

Views: 910

Answers (1)

Ankit Gupta
Ankit Gupta

Reputation: 672

Read from this link YouTube API

Upvotes: 1

Related Questions