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()");
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.
AFAIK, developer can't control that.
Even if developer control that by finding html element by getElementById method and click it, it'll be blocked if Google change the html structure.
I recommend the way is being provided by Google officially.
https://developers.google.com/youtube/android/player/
Related
I am planning to develop an Android App for Kids Leaning.
In the initial screen, i will have list of topics like below. These topics will be loaded from a Database and each link contains a href.
Now, once the kid click on any link, in the next activity, i am loading a WebView and the video is played in the WebView.
String frameVideo = "<html><body><iframe width=100%; height=100%; src="+strVideoURL+" frameborder=\"0\" allowfullscreen></iframe></body></html>";
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.loadData(frameVideo, "text/html", "utf-8");
Following is the screenshot how it looks like:
So is it legal to reference video as above?
In the above scenario, can i monetize the App. I dont want to show any Ads on the videoplayer activity, but wanted to place Ads on all other activities. Is it Legal? Please suggest.
I used a webView to play vimeo embed video. My webview works fine while playing youtube videos. But when I load vimeo video the thumbnail is shown in webview but when I click play button, a toast with message :Operation not allowed is displayed. Then whole screen goes grey with video icon in center.
Here is my webView code:
<WebView
android:background="#android:color/white"
android:id="#+id/webViewYoutube"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
And my fragment code to load video in webView.
String vimeoFrame="<html><body><iframe src=\"http://player.vimeo.com/video/113067409?autoplay=1&loop=1\" width=\"300\" height=\"200\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></body></html>";
WebView vimeoPlayer = (WebView) getView().findViewById(R.id.webViewYoutube);
WebSettings webSettings2 = vimeoPlayer.getSettings();
webSettings2.setJavaScriptEnabled(true);
webSettings2.setBuiltInZoomControls(false);
webSettings2.setAppCacheEnabled(true);
webSettings2.setDomStorageEnabled(true);
webSettings2.setPluginState(WebSettings.PluginState.ON);
vimeoPlayer.setWebChromeClient(new WebChromeClient());
vimeoPlayer.setWebViewClient(new WebViewClient());
vimeoPlayer.setLayerType(View.LAYER_TYPE_HARDWARE, null);
vimeoPlayer.loadData(vimeoFrame, "text/html", "utf-8");
UPDATE
Looking deep in Logcat, I discovered warning stacktrace which is like this:
java.io.FileNotFoundException: No content provider: https://s.vimeocdn.com/vimeo-prod-std-us/video/393408632.mp4?token=55afa9c1_0x34d715bffb7e3c81b0c424ee5a62862913e2c1e6
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:710)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:985)
at android.webkit.HTML5VideoView.prepareDataCommon(HTML5VideoView.java:309)
at android.webkit.HTML5VideoView.prepareDataAndDisplayMode(HTML5VideoView.java:346)
at android.webkit.HTML5VideoInline.prepareDataAndDisplayMode(HTML5VideoInline.java:57)
at android.webkit.HTML5VideoViewProxy$VideoPlayer.play(HTML5VideoViewProxy.java:265)
at android.webkit.HTML5VideoViewProxy.handleMessage(HTML5VideoViewProxy.java:416)
It appears that parsing of Embed Vimeo video url was not properly done by android. I tested same embed url with iOS which works fine. This issue is only with Android. Does anyone know how to solve this?
my probelm is how to play a video in a webview. i can setup a live french on 000webhost to stream in android.now the problem is how can i play in android using a webview... here is my code which can display a white screen i dont know why
mWebView = (WebView) findViewById( R.id.webView1 ); //This is the id you gave
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(true); //Zoom Control on web (You don't need this
//if ROM supports Multi-Touch
mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
// Load URL
mWebView.loadUrl("http://gumsuminnocent.host56.com/frenchchannel.html");
not working just white screen.
plz help me and Thanks in advance
sorry for my poor english
Use Webview, Create a string for html tags, add iframe tage and pass the height and width of the video and url. and load the string in webview
webView.loadData(strHTMLTags, "text/html", "UTF-8");
I am using the following data to display in a WebView. These are the HTML tags along with
the iframe which is referring to a video.
Now the problem is when I click on it, it shows the play button but cannot play the video.
Can I play this video inside WebView or not?
<p></p><P> because of Jon’s pro-growth, business-friendly policies, Utah's economy expanded at more than triple the national rate and was named the best state for business by <EM>Forbes.</em><BR /><BR /><IFRAME height=241 src="http://player.vimeo.com/video/25349114" frameBorder=0 width=425></iframe></p><br />
<P>America needs a dose of the same medicine. Today, our nation has the second highest corporate tax rate in the developed world. We have convoluted and confusing regulations.
<!--break--><!--break--><p></p>
when I try to run this url in the android browser it opens videoview and plays that file perfectly but why not in iframe?
http://player.vimeo.com/video/25349114
The key thing is to enable browser plugins.
// how to enable the webview plugin changed in API 8
if (Build.VERSION.SDK_INT < 8) {
mWebView.getSettings().setPluginsEnabled(true);
} else {
mWebView.getSettings().setPluginState(PluginState.ON);
}
Also worth checking flash player is installed
WebView wv;
wv = (WebView) findViewById(R.id.mywebview);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setBuiltInZoomControls(true);
wv.getSettings().setPluginsEnabled(true);
Use this code to load your video and also update the flashplayer of your device...
i tried to load the url ww.youtube.com on my app in a webview. but it cant be load completely. it loads just like below image. in the browser it loads comfortably. why? Any Idea?
image http://www.freeimagehosting.net/uploads/d7356dd8e1.png
the simple answer is to call the youtube app thats loaded on every phone with your webview. check out the code on http://fluxkore.com/index.php/android-apps/ to call the youtube app.....
Enable JavaScript! =)
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.youtube.com");
It might be a problem with WebViews - WebViews aren't fully fledged browsers, and have limited functionality. For example, the reference page specifically says that WebViews don't handle JavaScripts. If JavaScripts, Flash or something like that is required to properly load YouTube, then that could be why the WebView doesn't handle it properly.