1

I have a webview in my application which upon launch displays an html page. The page has a hyperlink which on click is supposed to display a video.

When i run the application and click on the video hyperlink link , nothing happens. But if i load the same page in android browser, then it launches a default video player and everything works fine.

I debugged it furthers by putting a log statement in shouldOverrideUrlLoading method and noticed that, when the hyperlink is clicked it gets redirected to another link and then to another link (final video streaming url).

My question is : why would the link work perfectly in default android browser and not through a webview.

Thanks

prashant
  • 3,570
  • 7
  • 40
  • 50
  • Are you sure it is redirect problem? I think the WebView does handle http redirect. Actually you will be a callback if there are too many redirects: http://developer.android.com/reference/android/webkit/WebViewClient.html#onTooManyRedirects(android.webkit.WebView, android.os.Message, android.os.Message). – dongshengcn Aug 22 '11 at 17:28
  • what kind of video are you trying to play? is it a video tag? or it is a direct link to a video file? These two cases are handled differently. Embedded WebView would not work for the video tag out of box. – dongshengcn Aug 22 '11 at 17:29
  • First url is this http://xxx.yyy.net/playVideo?siteId=xxx_web&userId=4e52948ebdf19&content=3000039950 1st Redirects looks like this http://stream.yyy.net/adservice/3000039950.3g2?rtspSID=20891189461314034834721605&ack=yes&auth=ffabf0505850792886dd6d5c26b90c68&res=16x9 2nd Redirects looks like this http://pd.vsnax.yyy.net/adservice/3000039950.3g2?rtspSID=20891189461314034834721605&ack=yes&auth=ffabf0505850792886dd6d5c26b90c68 – prashant Aug 22 '11 at 17:44
  • where is the video file? – dongshengcn Aug 22 '11 at 17:51
  • The link to video is [link](http://pd.vsnax.rnmd.net/adservice/3000039950.3g2?rtspSID=20891189461314036008198339&ack=yes&auth=1e221c61aefc1e7d46672ac19a072063&appId=cnbc_web&userId=cnbc_web-4e5299235334c&personCookie=208.91.189.46.4a96f172-49c2-4796-ae73-6d8d5930bda8&res=16x9&adinsert=1&redirect=true). If you click this on browser it will show a video. – prashant Aug 22 '11 at 18:01
  • did you try it? let me know if you encounter any problem. – dongshengcn Aug 23 '11 at 13:35
  • 1
    I tried this approach and now the video is playing. webView.setDownloadListener(new DownloadListener(){ ... }). but i'm really looking for a way to launch video player from html page, so that i don't have to a application release to resolve this issue. – prashant Aug 23 '11 at 13:49
  • I see. I doubt there is a way to do that. Let me know if you figure out a way. – dongshengcn Aug 23 '11 at 14:01

3 Answers3

1

After declaring your WebView you should set javascript enabled, then your WebView will work as a browser.

For example:

WebView mwebview = new WebView(this);
setContentView(mwebview);

mwebview.getSettings().setJavaScriptEnabled(true);

or

mwebview.getSettings().setPluginState(PluginState.ON); // this is for newer API's
biegleux
  • 13,179
  • 11
  • 45
  • 52
Barna
  • 11
  • 1
1

What is happening is when you click the hyperlink, that link probably has some popups inside of it. You need to define the onCreateWindow function in your webview's WebChromeClient. This handles how calls to open new windows or popups are handled.

public boolean onCreateWindow (WebView view, boolean dialog, boolean userGesture, Message resultMsg) {

    ((WebView.WebViewTransport) resultMsg.obj).setWebView(myWebView);
    resultMsg.sendToTarget(); 
    return true;
}
Pete
  • 3,842
  • 3
  • 31
  • 42
0

Basically, do not expect your embedded WebView works the same as Android default Browser. The default Browser is built on the same WebView, but there are lots a customization. (Especially around the no-standard uri, HTML5 stuff)

I followed code from here: WebView and HTML5 <video>, and I put the video link to a video tag, and I got the Video playing in my own version of WebView. The behavior is a little different from the default Browser. Given more time, we could figure that out by looking at its code, but anyways ...

Community
  • 1
  • 1
dongshengcn
  • 6,434
  • 7
  • 35
  • 44