I'm trying to show one local html file contains code for playing video and try to show that html file in android webview.
I've used following code to for playing video:
//DECLARE webview variable outside of onCreate function so we can access it in other functions (menu)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings(); // Fetches the
// WebSettings
// import
WebViewClient webViewClient = new WebViewClient();
webView.setWebViewClient(webViewClient); // Enabling mp4
webSettings.setPluginsEnabled(true); // Allows plugins to run which are
// normally disabled in webView
webView.getSettings().setBuiltInZoomControls(true); // Allows the
// Android built in
// zoom control
webView.getSettings().setSaveFormData(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setLightTouchEnabled(true);
webView.getSettings().setAllowFileAccess(true); // To allow file
// downloads/streams
// such as mp4, mpeg,
// and 3gp files
webView.getSettings().setJavaScriptEnabled(true); // Enables HTML
// Javascript to run
// in webview
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setSupportZoom(true); // Support the zoom feature
webView.getSettings().setSavePassword(true); // Allow users to save passwords in forms
webView.setWebViewClient(new WebViewClient() { // Opens web links clicked by user in the webview
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) { // Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl("file:///android_asset/test.html"); // test.html file from assets folder
//... Rest of activity code...
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls="controls">
<source src="http://www.w3schools.com/html/movie.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>
</body>
</html>
Android webview or Android Default Browser shows the video content in another video view when we click play button, My requirement is that video should be opened in same html page inline, so user can navigate to other page of webpage during video is playing or buffering.
I tried many other ways like, video tag of HTML5 embed tag of HTML object tag of HTML
Other way of video player integration i checked so far but not worked in my requirement,
Flare Video
jplayer
Please suggest me any way that can be suitable for my requirement, And my requirement is very simple as, I want to play video in html file as inline in webview widget of android.
Thanks in Advance.
您必须使用webView Custome类来播放mp4视频
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.