problem in playing video on android webview using HTML5?
this is my html file...
<html>
<head> Demo </head>
<body>
<h1>HTML 5 - Video Demo</h1>
<video src="http://www.abc.com/a.m4v" controls="true">
</video>
<script>
document.getElementById('video');
</script>
</body>
and I'm using this code for java...
public void onCreate(Bundle savedInstanceState) {
super.onCreate开发者_如何学编程(savedInstanceState);
this.setContentView(R.layout.viewr);
WebView web = (WebView) findViewById(R.id.webview);
web. getSettings().setJavaScriptEnabled (true);
web.getSettings().setAllowFileAccess(true);
web. loadUrl ("file:///android_asset/VidDemo.htm");
web.setWebViewClient(new MyWebViewClient());
}
final class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".3gp")) {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} else {
return super.shouldOverrideUrlLoading(view, url);
}
}
}
but video not appear on screen and also not play. please suggest me what should i do...
That is because Android's browser does not have any video codecs.
Somehow, you will have to trigger the native video app to open on click. I am looking for a way to do that too.
It works
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
webView.getSettings().setPluginsEnabled (true);
webView.getSettings().setSupportMultipleWindows (false);
webView.getSettings().setSupportZoom (false);
webView.setVerticalScrollBarEnabled (false);
webView.setHorizontalScrollBarEnabled (false);
webView.getSettings().setFixedFontFamily("file:///android_asset/fonts/CamMob.ttf");
webView.getSettings().setDefaultFontSize(fontSize + 5);
webView.setWebViewClient(new MyWebViewClient());
webView.setWebChromeClient(chromeClient);
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
}
private WebChromeClient chromeClient = new WebChromeClient(){
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
if(view instanceof FrameLayout){
FrameLayout frame = (FrameLayout)view;
if(frame.getFocusedChild()instanceof VideoView){
VideoView video = (VideoView)frame.getFocusedChild();
frame.removeView(video);
video.start();
}
}
}
};
精彩评论