Animations / Videos on GUI

Hi,

is there a way to use animations (.gif) or videos on a gui?

For example, in my pre-lobby loading screen, i would like to have a rotating loading icon. How can i do that?

Hey,

there are some ways you can do that. I’m not quite sure if gif files are supported, but video files in general are loaded through FFMPEG, so it might be.

To load an animation/video file you’ll simply load it as a texture and apply it on a frame or whatever GUI widget you want to use. E.g.:

from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectFrame import DirectFrame

from panda3d.core import loadPrcFileData
# Make sure textures-power-2 is set to none
# otherwise you'll get a black border around your video 
loadPrcFileData("", "textures-power-2 none")

app = ShowBase()

myMovieTexture = app.loader.loadTexture("path/to/my/movie.ogv")
myFrame = DirectFrame(image=myMovieTexture)
myMovieTexture.play()

app.run()

Further details can be found here in the Manual:
https://docs.panda3d.org/1.10/python/programming/texturing/playing-mpg-and-avi-files

Alternatively you can also convert your video to an egg file and load that instead. The steps to do so are described in this manual section:
https://docs.panda3d.org/1.10/python/programming/texturing/automatic-texture-animation

hi there,
i tried your code but the video was not playing in full screen mode, leaving grey bands on the sides.

So instead, i tried to figure out the code provided in the panda3d example progam:

self.tex = MovieTexture("name")
success = self.tex.read("Assets/4k/Videos/intro2.mp4")
assert success, "Failed to load video!"
  
# Set up a fullscreen card to set the video texture on.
cm = CardMaker("My Fullscreen Card")
cm.setFrameFullscreenQuad()
  
# Tell the CardMaker to create texture coordinates that take into
# account the padding region of the texture.
cm.setUvRange(self.tex)
  
# Now place the card in the scene graph and apply the texture to it.
card = NodePath(cm.generate())
card.reparentTo(base.render2d)
card.setTexture(self.tex)
  
self.sound = base.loader.loadSfx("Assets/4k/Videos/intro2.mp4")
# Synchronize the video to the sound.
self.tex.synchronizeTo(self.sound)

but here i have two problems:

the video plays in loop, and i don’t see an obvious way to stop it from the documentation;
my video contains only a short bit of audio in the middle, but if i try to run the code with the last two lines (self.sound = base.loader... and so on) the video doesn’t play, it is stuck in its first frame.

Thanks, Tom.

Hey,

Panda3Ds default is to loop media. You can simply set that with a call of self.sound.setLoop(False)

As for the video not playing, did you call self.sound.play in your actual code? Since, it’s not in the lines you posted here. Otherwise it will only get loaded and displayed, not started. Also, just to make sure you didn’t miss this detail, you will control the video via the audio file once it’s synchronized to it.