2011-07-06 07:15:56 +00:00
|
|
|
"""
|
|
|
|
Basic Video Playback
|
|
|
|
++++++++++++++++++++++
|
|
|
|
Example of how to replace a texture in game with a video. It needs to run everyframe
|
|
|
|
"""
|
|
|
|
import bge
|
|
|
|
from bge import texture
|
|
|
|
from bge import logic
|
|
|
|
|
|
|
|
cont = logic.getCurrentController()
|
|
|
|
obj = cont.owner
|
2011-07-29 01:24:03 +00:00
|
|
|
|
|
|
|
# the creation of the texture must be done once: save the
|
2011-07-06 07:15:56 +00:00
|
|
|
# texture object in an attribute of bge.logic module makes it persistent
|
|
|
|
if not hasattr(logic, 'video'):
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:15:56 +00:00
|
|
|
# identify a static texture by name
|
|
|
|
matID = texture.materialID(obj, 'IMvideo.png')
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:15:56 +00:00
|
|
|
# create a dynamic texture that will replace the static texture
|
|
|
|
logic.video = texture.Texture(obj, matID)
|
|
|
|
|
|
|
|
# define a source of image for the texture, here a movie
|
|
|
|
movie = logic.expandPath('//trailer_400p.ogg')
|
|
|
|
logic.video.source = texture.VideoFFmpeg(movie)
|
|
|
|
logic.video.source.scale = True
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 07:15:56 +00:00
|
|
|
# quick off the movie, but it wont play in the background
|
|
|
|
logic.video.source.play()
|
|
|
|
|
|
|
|
# you need to call this function every frame to ensure update of the texture.
|
2011-07-13 00:49:22 +00:00
|
|
|
logic.video.refresh(True)
|