I want to play video url inside my application webview but when i am run the application it showing only white screen . i had read some post on this and i have used that cod
For me this was the solution
settings.setDomStorageEnabled(true);
WebView webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.getSettings().setPluginState(WebSettings.PluginState.ON);
webview.getSettings().setMediaPlaybackRequiresUserGesture(false);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("https://www.youtube.com");
also set in manifist file
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Try this.
{
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setMinimumFontSize(10);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
webView.setVerticalScrollBarEnabled(false);
webView.loadDataWithBaseURL(null, vUrl, "text/html", "UTF-8", null);
}
No you can't play the video by link in this case. To do this you should create an RTSP connection then you can play the video through an RTSP url in Webview
. You can retrieve an RTSP connection from a server like Youtube.
This may be an old question but this works:
//Here Im loading the html file from disk
String html_file = LoadData(file.getAbsolutePath());
WebView myWebView = (WebView) view.findViewById(R.id.webView);
myWebView.reload();
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadData(html_file, "text/html; charset="utf-8", "UTF-8");
Use base64 encoded video data as your video
source:
//html_file
<video controls>
<source type="video/mp4" src="data:video/webm;base64,MY_BASE64_ENCODED VIDEO_HERE">
</video>
You need to load an HTML document that embeds the video inside of it, instead of the video directly. To play inline video in WebView using the <video>
tag you must also ensure the hardware acceleration is enabled in your application (see http://developer.android.com/guide/topics/graphics/hardware-accel.html).