Play a local swf-file (flash) with webview?


Last Updated:

  1. xtreme

    xtreme New Member This Topic's Starter

    Joined:
    May 4, 2010
    Messages:
    4
    Likes Received:
    0
    I guess webview is the best solution to play a local swf-file (flash). I just get cryptic character in the emulator with this html code in webview.

    HTML:
    1.  
    2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3. <html xmlns="http://www.w3.org/1999/xhtml">
    4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    5. <title>Flash</title>
    6. </head>
    7.  
    8. <object width="550" height="400">
    9. <param name="movie" value="Flashfile.swf">
    10. <embed src="Flashfile.swf" width="550" height="400">
    11.  
    12. </body>
    13. </html>
    14.  
    15.  
    How can i play a local swf-file when the user click on some kind of link, java or html?
     

    Advertisement
  2. Profete162

    Profete162 Member

    Joined:
    Dec 18, 2009
    Messages:
    9
    Likes Received:
    0
    Same question here, sorry to spam this forum, but this question was asked several times, and I could n t find any clue..
     
  3. ab0mbs

    ab0mbs Member

    Joined:
    Feb 6, 2011
    Messages:
    5
    Likes Received:
    2
    If you want to play it in a webview you would first need to create your webview with these settings

    Code (Text):
    1.  
    2.  
    3.         mWebView = (WebView) findViewById(R.id.webview);
    4.         mWebView.getSettings().setJavaScriptEnabled(true);
    5.         mWebView.getSettings().setPluginsEnabled(true);
    6.  
    You can then load data into the webview like so
    Code (Text):
    1.  
    2.  
    3.         String html = "<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///sdcard/flash/2204355.swf\"> <embed src=\"file:///sdcard/flash/2204355.swf\" width=\"550\" height=\"400\"> </embed> </object>";
    4.         String mimeType = "text/html";
    5.         String encoding = "utf-8";
    6.        
    7.         mWebView.loadDataWithBaseURL("null", html, mimeType, encoding, "");
    8.  
    I simply made custom html inside the program and told it to load a flash file that I had stored in the flash folder on my sdcard.

    keep in mind that in the custom html you have to escape the " with a back slash like this \" so that it wont end the string. You also have to have it all on one line unless you want to append strings together like so

    Code (Text):
    1. String myString = "something" + "something else"
     
    powerpoint45 and CBarbas like this.
  4. Profete162

    Profete162 Member

    Joined:
    Dec 18, 2009
    Messages:
    9
    Likes Received:
    0
    Yes, thank a lot, but by a local file, I meant a file from the asset folder.

    Of, course, I can copy it to the SdCard, but wouldn't it be better and cleaner for the user to use the asset folder, something like:


    Code (Text):
    1. value=\":///[B]asset folder[/B]/2204355.swf\"
    Thank a lot.
     
  5. ab0mbs

    ab0mbs Member

    Joined:
    Feb 6, 2011
    Messages:
    5
    Likes Received:
    2
    if you want to use a file in the assets folder you would just have to change this part of the html string from this
    Code (Text):
    1.  
    2. <param name=\"movie\" value=\"file:///sdcard/flash/2204355.swf\"> <embed src=\"file:///sdcard/flash/2204355.swf\" width=\"550\" height=\"400\">
    3.  
    and change the value and src parts to this

    Code (Text):
    1.  
    2. <param name=\"movie\" value=\"file:///android_asset/2204355.swf\"> <embed src=\"file:///android_asset/2204355.swf\" width=\"550\" height=\"400\">
    3.  
    All you have to do is put the file in the assets folder. And make sure when you add it to your project that you copy the file in and not just link to it
     
  6. Profete162

    Profete162 Member

    Joined:
    Dec 18, 2009
    Messages:
    9
    Likes Received:
    0
    Just amazing!
    One of my client is asking for a tablet-sized presentation for his marketting team.
    They wanted to make an interactive presentation of their products.

    Making animations with Android was really hurting and painful!
    Flash just saved my life.

    Thank a lot, man!
     
  7. fou

    fou New Member

    Joined:
    Mar 24, 2011
    Messages:
    1
    Likes Received:
    0
    Hi
    I try this code but the swf didn't display into the webview.

    Code (Text):
    1. public void onCreate(Bundle savedInstanceState) {
    2.         super.onCreate(savedInstanceState);
    3.         setContentView(R.layout.main);
    4.         objectview= (WebView)this.findViewById(R.id.webkit);
    5.         //ex
     

    Attached Files:

    • im.JPG
      im.JPG
      File size:
      4.4 KB
      Views:
      11
  8. yogidk

    yogidk New Member

    Joined:
    Apr 6, 2011
    Messages:
    2
    Likes Received:
    0
    public void onCreate(Bundle savedInstanceState) {
    WebView mWebView;
    super.onCreate(savedInstanceState);

    setContentView(R.layout.
    main);
    mWebView =(WebView) findViewById(R.id.​
    webview);
    mWebView.getSettings().setJavaScriptEnabled(
    true);
    mWebView.getSettings().setPluginsEnabled(
    true);

    String html = ​
    "<object width=\"550\" height=\"400\"> <param name=\"movie\" value=\"file:///android_asset/changing_tyres.swf\"> <embed src=\"file:///android_asset/changing_tyres.swf\" width=\"550\" height=\"400\"> </embed> </object>";
    String mimeType =
    "text/html";
    String encoding =
    "utf-8";
    mWebView.loadDataWithBaseURL(
    "null", html, mimeType, encoding, "");

    }


    I have used the above code to display my swf file changing_tyres.swf. But the screen is blank when i run in the emulator. I have just followed the code that was written above. Only thing that I changed was the swf file. Could you please tell me what could have gone wrong or why the screen is blank.

     
  9. summitch

    summitch New Member

    Joined:
    Jul 17, 2011
    Messages:
    1
    Likes Received:
    0
    Note: I'm using an Asus Transformer and trying to launch a simple webview app in 3.1 (API lvl 12).

    I am having the same issue.

    I've seen the code above all over the place (StackOverflow and the like), and it's all pretty much identical, but none of it works.

    When I run it, I get a black screen. If I change the file name, I get "Webpage not available," so I'm pretty sure that's correct.

    I think it has something to do with the plugin. If I use the standard browser, I can hit flash games just fine. However, I navigated to a Facebook game with the webview app that I made, and the game doesn't appear. There's a white space allotted for it, and oddly, the music is playing, but the game doesn't appear.
     
  10. CBarbas

    CBarbas New Member

    Joined:
    Sep 17, 2011
    Messages:
    1
    Likes Received:
    0

    You have

    saved me with this. I have searched allover for this solution!


    Thanks
     
  11. danuchiha

    danuchiha New Member

    Joined:
    Jan 10, 2012
    Messages:
    1
    Likes Received:
    0
    I have a game in a swf file, is there a possibility to make an application for android in Eclipse where user can in their own mobile invoke and play with this .swf ? (maybe from a webView?)

    can I do it using FLEX? but I don't have a concrete idea

    (sorry is the theme is repetitive here, i couldn't find something that can help me)

    hope you guys can help me :confused:
     
  12. freefulltime

    freefulltime New Member

    Joined:
    Aug 24, 2015
    Messages:
    2
    Likes Received:
    0
  13. Mina Nabil

    Mina Nabil New Member

    Joined:
    Mar 15, 2016
    Messages:
    1
    Likes Received:
    0
    hi can you help me and make it video please in eclipse
    thanks in advance
     

Share This Page

Loading...