Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Flash en webview Android, videos youtube

I am trying to show videos of youtube in the webview for Android. I use this code:

var webview = Titanium.UI.createWebView({
top:45,
left:0,
height:360,
width:320});

var entryVideo = 'http://www.youtube.com/v/???????';

var html = '<html><body><div><embed id="yt" src="'+entryVideo+'" type="application/x-shockwave-flash" width="300" height="150"></embed></div></body></html>';


webview.html = html;

However, nothing is shown, the webview is empty, unlike the iPhone, where the same code works fine (shows a preview image of the video).

I have found out, that <b> in Java </b> it is necessary to call getSettings().setPluginsEnabled(true) for the WebView class, to enable plugins como Flash.
It is similar to calling <b> in Java </b> getSettings().setJavaScriptEnabled(true)
to enable Javascript.

I found the source code of Appcelerator here:

http://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiUIWebView.java

I see, that setJavaScriptEnabled(true) is called, but setPluginsEnabled(true) is NOT called. Seems like plugins are not enabled for the implementation of WebView for Android.

Is it true? Is it intentional or is it a bug?

How can I show the videos of Youtube on android in this case?

— asked August 9th 2010 by Anna Kozynenko
  • android
  • flash
  • webview
  • youtube
2 Comments
  • I am curious about this same issue. Is there a way to setPluginsEnabled = true from the API?

    — commented August 16th 2010 by Zach Wilson
  • It looks like setPluginsEnabled has been deprecated and replaced with setPluginState.

    — commented August 16th 2010 by Zach Wilson

8 Answers

  • Well, it's my other incarnation with a different email. I finally ended up using YouTube player, it does work if u use OpenURL and URL like their urls, http://www.youtube.com/watch?v=…

    The Appcelerator people are unsure, if they should enable plugins, because many older Android phones are not flash-enabled (they use something like Flash Lite)

    I would say, they should, at least give an option in the property list of webview.

    — answered August 20th 2010 by Ganna Kozynenko
    permalink
    0 Comments
  • We need to have option to enable plugins especially flash appcelerator please

    — answered July 14th 2011 by Lukas Skrabak
    permalink
    0 Comments
  • This issue is still appearing with mobileSDK 1.8 nightly build. One workaround I found was to use Titanium.Platform.openURL(&#39;http:&#x2F;&#x2F;your.url&#x2F;&#39;); to open the page in the native browser, but this does not share session data with in app webviews, and it opens on top of instead of inside of your app.

    I'm going to try writing a module to extend the Titanium webview to add setPluginsEnabled(true) to the webview setup code and report results.

    — answered August 11th 2011 by Tom Ferch
    permalink
    2 Comments
    • I tried this about a month ago and couldn't get it to work even with a custom titanium module. If you get it to work I'd love to know!

      — commented August 13th 2011 by Uri Shaked
    • Hi Tom Frech,

      we are using samsung 10.1 tab ( Android 3.1).Flash content not working properly.we can hear the sound.but cannot view the content.

      In (Android 2.2),it is working fine. For this i tried the same technique as u said in above comment, i.e, we enabled plugin in webview class file and also we changed API 7 to API 8 in sconstruct.

      Will u pls tell me the further changes, if anything required to do to make it work in Android 3.1.

      please help me this matter.waiting for your help.

      Thans in Advance
      Vinod…

      — commented September 20th 2011 by vinod varghese
  • If you need a flash plugin (or other plugins) in your webview then go to githbu download the newest titanium_mobile_sdk and make changes in the java source for android SDK. Use google like "android webview setPlugins(1)" I think there is a guide on stackoverflow

    — answered August 14th 2011 by Lukas Skrabak
    permalink
    3 Comments
    • I'm trying this method, I've made the required change to the webview code, but I can't build the SDK because of 100 java compile errors in the Map module; I don't really have time to fix all that broken code, and it seems very strange to me that the SDK is filled with build errors. Build output is at http://pastie.org/2398346 for reference.

      — commented August 19th 2011 by Tom Ferch
    • well if I were you I would check my workstation if I have latest java, scons and other stuff needed to compile successful titanium_mobile_sdk build. Otherwise I'm unable to help you as I was not able to reproduce your errors.

      — commented August 19th 2011 by Lukas Skrabak
    • Found the solution to the problem, turns out I didn't have an old enough Android SDK installed - it was trying to target 7, but I only have 8 or newer set up. I changed the default to 8 in SConstruct and it built fine. Additionally, once it built, Flash did work in the webview (on Android 2.3 device)!

      — commented August 23rd 2011 by Tom Ferch
  • Hi Tom Ferch,

    Dear friend,, we saw your comment on flash in Android webview. will u please explain detail how to achieve this. we are using Titanium to develop native application for Samsung galaxy tab.

    Pls help in this matter, thanks in advance.

    Regards
    Vinod Varghese

    — answered August 24th 2011 by vinod varghese
    permalink
    4 Comments
    • The method that worked for me in the end was:

      1. Clone the Titanium Mobile SDK from github

      2. In the Android SDK, find TiUIWebView.java and add the line settings.setPluginsEnabled(true); to the constructor.

      3. Build the SDK using scons (note that the SConstruct file defaults to look for Google API 7, if that is not the version you want to build with, change it in SConstruct).

      4. Unzip the archive that scons created under dist/ into the folder where your Titanium SDKs are located.

      5. Change the Project Properties to use the new version of the SDK and rebuild the project.

      This set of steps worked for me, though I had a few snags at SDK compilation. Best of luck to you.

      — commented August 25th 2011 by Tom Ferch
    • Thansks for the comments dear.i will try and let you know..

      — commented August 26th 2011 by vinod varghese
    • Dear Tom Ferch,

                Once again thank you a lot for your respose.i tried and it was succesfull in android device.but in emulator it is not working.
      

      — commented September 6th 2011 by vinod varghese
    • Could you please specify how can I do this?

      Please give a detailed answer

      Thanks

      — commented September 6th 2011 by Sreekumar K U
  • Hi Tom Ferch,

    I find your answer here. But I don't know how to do it, because I a beginner to appcelerator.

    Please please please if you explain it in some more detail, it will be very helpful for me.

    — answered September 19th 2011 by Sreekumar K U
    permalink
    0 Comments
  • TIMOB-1607 is in CI 1.8.0. There is example code in the JIRA issue.

    — answered September 19th 2011 by Don Thorp
    permalink
    0 Comments
  • — answered August 20th 2010 by Ganna Kozynenko
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.