1

I tried many times and try to use HTML tag <object>, but app just crash and disappear.

Each time when I use normal html tag such as <html>, <body>, <h1>, <div>, <td>, <tr> etc. Those can be shown directly without any error.

This time I try to embed an <object> tag to webview and it always crash! Does anyone who know how to do this directly inside code? OR, webview just cannot do this?

here is my code.


String html = 
  "<html>" +
  "<body><h1>This is a test !!</h1>" +
  "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='200' height='200'></object>" +
  "<param name='quality' value='high'>" +
  "<param name='allownetworking' value='internal'>" +
  "<param name='allowScriptAccess' value='never'>" +
  "<param name='movie' value='http://video.yutube.com/flv2.swf?i=20100129LqvamMPB&amp;d=360.25&amp;movie_stop=off&amp;no_progressive=1&amp;otag=1&amp;sj=5&amp;rel=1'>" +
  "<param name='allowFullScreen' value='true'>" +
  "<embed src='http://video.yutube.com/flv2.swf?i=20100129LqvamMPB&amp;d=360.25&amp;movie_stop=off&amp;no_progressive=1&amp;otag=1&amp;sj=5&amp;rel=1' width='200' height='200' quality='high' allownetworking='internal' allowscriptaccess='never' allowfullscreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed>" +
  "</object>" +
  "</body></html>";

mWebView.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Neo
  • 11
  • 3

2 Answers2

1

You have one <object> tag and two </object> tags. The first </object> has got to go.

The embed tag is for browsers that don't recognize the object tag. Those browsers will see the embed tag and will try to use it. Browsers that support the object tag will use the object and ignore the embed, as long as the embed is within the object. If the embed is outside the object, object aware browsers may load both the object and embed tags.

0

WebView can definitely handle the html tag. I don't think you should use loadDataWithBaseURL though, try this instead:

mWebView.loadData(html, "text/html", "UTF-8");

I'm not too sure your <object> will work though...

Here's a better way to play a YouTube video if that's all you need:

startActivity(new Intent(Intent.ACTION_VIEW, 
   Uri.parse("http://www.youtube.com/watch?v=<video-id>")));

Put your video id in place of the <video-id>

Alan Moore
  • 6,525
  • 6
  • 55
  • 68
  • This time I take your suggestion and change to mWebView.loadData(), the APP does not crash anymore, but instead, it shows empty white screen. I put a web html page to a WebServer with the same setting, and I use mWebView.loadUri(). It work fine. I can see youtube video, but I plan to move this webpage to APP itself, and nothing is working so far! Any other suggestion? – Neo Sep 09 '11 at 05:00
  • I tried may times. I use this web page to load by .loadUrl(), and it works fine, but when I put those html content as a String html, and feed it to .loadData(), and it just simply not works ! – Neo Sep 09 '11 at 06:59
  • I think you should probably try this other approach if what you want is to display a YouTube video (see code above) or this might work better too: http://stackoverflow.com/questions/3458765/how-to-embed-a-youtube-clip-in-a-webview-on-android – Alan Moore Sep 09 '11 at 13:24