E Gomez
E Gomez

Reputation: 77

Redirecting to a video with http-equiv="refresh" meta-tag doesn't work in Android embedded browser

I want to start playing a video after 3 seconds after loading a web page. This is my html code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta http-equiv="refresh" content="3;url=http://xx.xxx.x.xxx:8080/small.mp4"/>

</head>

<body>
    <ul>
        <li><a title="Home" alt="Home" href="/">Home</a></li>

    <li><a title="Match Centre" alt="Match Centre" href="/menu/centre">Match Centre</a></li>

    <li><a title="Clubs" class="more clubs" href="/menu/clubs"><span>Clubs</span></a></li>

    <li><a title="Menu" class="more menu" href="/menu/options"><span>Menu</span></a></li>
    </ul>
</body>
</html>

It works perfectly fine in all the browsers I have tried with (including the Android noraml browser), but it doesn't work with the Android embedded browser.

This is my main activity:

public class MainActivity extends Activity {

private WebView webView;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) {
                Log.e("CEmbeddedBrowser eceivedError()", "Fail to load: " + failingUrl);
            }

        });

        webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
            new AlertDialog.Builder(view.getContext())
                    .setMessage(message)
                    .setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            result.confirm();
                        }
                    })
                    .setCancelable(false)
                    .create()
                    .show();
            return true;
       }

    }); 
    webView.loadUrl("http://xx.xxx.x.xxx:8080/mypage.html");

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

Android documentation says the WebViewClient supports meta tags. I have tried the redirection with a normal page (http://www.google.com">) and it works, however I don't know why it doesn't work with a video.

Upvotes: 1

Views: 1280

Answers (1)

Mr. Buster
Mr. Buster

Reputation: 111

To any others looking for a solution to this like I was, it turns out that I had to specify WebViewClient as the target for navigation. The meta refresh/redirect seems to be treated like a navigation activity so as soon as I told webview to handle navigation within itself it worked perfectly.

Google Developer Documentation:

Handling Page Navigation

When the user clicks a link from a web page in your WebView, the default behavior is for Android to launch an application that handles URLs. Usually, the default web browser opens and loads the destination URL. However, you can override this behavior for your WebView, so links open within your WebView. You can then allow the user to navigate backward and forward through their web page history that's maintained by your WebView.

To open links clicked by the user, simply provide a WebViewClient for your WebView, using setWebViewClient(). For example:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());

Upvotes: 1

Related Questions