We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone !!
I need with the gif's in android mode. GifAnimation library is not working on adroid mode. I have tried running my on android. It works on PC but crashes at start on android. Here's an example :
import gifAnimation.*;
Gif loopingGif;
public void setup() {
size(400, 200);
loopingGif = new Gif(this, "lavalamp.gif");
loopingGif.loop();
}
void draw() {
background(255);
image(loopingGif, 10, 10);
}
I have coded the entire thing but it dosent works on android.. Need some suggetions.
Thanks a lot !
Answers
@SuyashN=== for that you can use the android web view class with an html+gif
@akenton I have written the code for a full game on processing. The code I wrote above is just the example to show my problem. What I am doin is a lot more then just playing the gif. So I need a solution to run the gif on android using Processing's android mode...
@akenaton I was working in an example but I couldn't get it to run. This is the line I am using to execute following details from *** WebView ***:
When I execute the application, it doesn't seem to load the gift. Instead, in the webview it shows a boxed msg: "This will display an animated GIF" with a broken generic icon pic in the upper left corner.
Any suggestions of how to get it to display?
Kf
@SuuyahN=== i dont understand:i answered to your question! - for using gif in android mode: : webview class + html... @kfrager: normally in android "native" you have to put your html (with the gif) in the assets folder; never tried with P5 but try yourself!!! (dont forget to add some line of code on the html head in order to adapt to viewport):: code example from an app i have published::
@akenaton I was able to compile the program but I have to save the .gif file in my android storage manually before running the sketch. Originally I have placed my gif file in my data folder within my sketch folder, as usual. However the problem rises when you load the gif in webview. When you call
mWebView.loadUrl("file:///android_asset/www/vinyl.html");
I am not sure if loadUrl knows where the android asset folder is located. However if I provided a full path directing to a known location on my phone, it works.
So I have a question for you: Is it possible to retrieve the full path of the android_asset folder? I think that will solve the problem.
@SuyashN Can you tell us more abut your problem? What other things do you do with your gif files?
Kf
@akenaton Never mind... your line works:
webview.loadUrl("file:///android_asset/lavalamp.gif");
I thought this line would work only from eclipse but I did not know I could use it for processing. Here it is the sample code and ensure your gif file is within your sketch folder in the data folder:
I hope this helps,
Kf
@kfrajer i have developed a game which uses gif to show its elements animated. I used the gifAnimation library by Patrick Meister to load and play the animation. It worked fine in java mode but crashes on start in android mode. This is the entire code:
Basically in this code as you can see I am displaying the gif and hiding them when various conditional statements or condition statements inside loops are fulfilled after or before certain duration of time.
This is done inside void loop().
To debug the problem I tried to run a simple code (which I have shown in the first post of this thread) only displaying a gif using the gifAnimation library. The same crash occurred. This meant that the library isn't working on android mode.
And now I need a solution which needs least changes in the working code I have written. It would be great if you could explain me the solution in this context. ..
Thanks a lot!! You are being a great help. :)
Did you run the code that I posted? You can position the webview in any location in your sketch and I believe you should be able to change the visibility dynamically.
I will suggest to come up with a reduce version of your code where you implement your gif functionalities that you want and merging it with webview. Then test your code ensuring it run properly in android. I am not sure if webview is the solution to go as you will be loading several of them. It might work but I don't have much experience implementing several of them at once.
You can always post in the forum if there are some alternate methods to display gif files in android mode.
If you want your code to work in Android and the gif library doesn't work, then you have two options. Make your app only PC runnable OR you wil have to put some extra effort to make it work in android. That is, you might have to change your code to adapt it to new tools.
If you implement a shorter version with the code I provided you, I could assist further. However I won't be able to work in your original code.
Kf
@SuysahN===
looking to your code i understand that using gif is more complicated than i thought (webview class); of course you can dynamically hide or show a web view (which inherits View) but with this workaround you cannot show or hide this one or this other gif (on the same html); one solution could be to use the frames from your gifs, put them in an arrayList() then get them and put them in a simple view in a relativelayout: so you can start, pause, loop or stop the gif and you can set the view where you want...Another one, more elegant, could be to make your webwiew client from your html adding to that javaScript methods: start, stop and so on, then sending from processing calls to theses methods.Last one could be to create multiple html: first with this gif running looping, second one with 2 gifs running, third one with 2 stopped gifs etc, according to your code: after that you change the webwiew contents.