GIF playback by filename


#1

Finally have some time to get back to learning a little more but got stuck on this…

Instead of randomly playing gifs is it possible to select a gif to playback via its filename?

Thanks
Daniel


How do you Play GIF files with push button trigger
#2

Hi Daniel, I assume you’re using the AnimatedGIFs example sketch. You can look at the code in FilenameFunctions, and pull out what you need:

    file = SD.open(pathname);
    if (!file) {
        Serial.println("Error opening GIF file");
        return -1;
    }

Put your hardcoded filename with path where pathname goes. If you’re not sure what the full file with path should look like, look at the serial output when running the sketch.

You might want to write your own function to open a specific GIF by filename, replacing the call to openGifFilenameByIndex() with your own function instead.

Hope that helps


#3

Thanks Louis,
Yes using your GIF’s example.
Adding the path to file = SD.open(pathname); works and displays any file you put in there which is great.
Im just a little stuck on how to start the new separate function that will open a specific GIF.


#4

Make a copy of getGIFFilenameByIndex() in both FilenameFunctions.cpp and FilenameFunctions.h. Rename the function. Edit the new function as it suits you. You can pass in the filename you want to open instead of directory name. You can remove index as you don’t need it.


#5

Thanks Louis, works as wanted now…

Is there a size/length limit to gif playback ?


#6

If there is a limit, I don’t know that anyone has hit it yet. Playing back a minutes-long GIF should work just fine.


#7

When i try to replace pathname with the file i want to run get this error message.
FilenameFunctions.cpp: In function ‘int openGifFilenameByIndex(const char*, int)’:
FilenameFunctions.cpp:135: error: ‘DinoRun1’ was not declared in this scope
file = SD.open(DinoRun1.gif);

                ^

Multiple libraries were found for "SD.h"
Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
Not used: C:\Program Files\Arduino\libraries\SD
’DinoRun1’ was not declared in this scope


#8

At a minimum, you need quotes around the filename.

file = SD.open("DinoRun1.gif");

You might need a longer path, e.g. “/gifs/DinoRun1.gif”


#9

Hi Louis,

Have now done that when i use the short path name it dose not display any thing, and when i use the longer one it comes up with no sd card. But when i go back to using pathname it works. What is going on?

Thanks


#10

Ah got it did not like the file name i was using, used one from the serial monitor and worked.

Thanks


#11

Hi feel like im realy close to atcheving getting this working with a push button keeps on coming up with this error message.

FilenameFunctions.cpp: In function ‘int openGifFilenameByIndex(const char*, int)’:
FilenameFunctions.cpp:157: error: expected ‘}’ at end of input
}

 ^

FilenameFunctions.cpp:157: error: expected ‘}’ at end of input
FilenameFunctions.cpp:157: warning: control reaches end of non-void function
}

 ^

Multiple libraries were found for "SD.h"
Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
Not used: C:\Program Files\Arduino\libraries\SD
expected ‘}’ at end of input


#12

Sorry I overlooked this message. I hope you got it figured out. It looks like you just have an extra curly brace in your code somewhere.