1

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...

1

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

To follow up, parse requests made inside your WebView and create an Intent to open the video player with any video url.
0

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();

            }
        }
    }

};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.