Issue
I am loading a youtube video in a webview and it works fine, what i wan't is to be able to control the video (i.e start , stop etc.) programmatically. I tried a few things and it didn't work
String playVideo= "<html><body><iframe width=\"100%\" height=\"100%\" src=\"https://www.youtube.com/embed/QKm-SOOMC4c?enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe></body></html>";
myWebView = (WebView) findViewById( R.id.Webview );
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
myWebView.loadData(playVideo, "text/html", "utf-8");
myWebView.loadUrl("javascript:playVideo()");
Solution
You can look at how I'm doing it in this library: android-youtube-player.
You can start by looking at the WebView class.
The idea of calling webview.loadUrl("javascript:playVideo()"); is correct. But you need to wait for the IFrame library to be loaded and ready.
Answered By - Pierfrancesco Soffritti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.