Android webview doesn't playing mp4 video in same page
Posted
by
user1668105
on Stack Overflow
See other posts from Stack Overflow
or by user1668105
Published on 2012-09-13T09:35:39Z
Indexed on
2012/09/13
9:38 UTC
Read the original article
Hit count: 595
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:
WebViewLoadVideoActivity.java
//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...
test.html
<!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>
Problem Area :
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.
Research Area :
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.
© Stack Overflow or respective owner