kivy putting video inside a Canvas?

混江龙づ霸主 提交于 2020-06-17 15:23:45

问题


i want to put a video inside a canvas.

i'm using images inside them just fine but when i use videos it triggers some errors Unknown <mp4> type, no loader found. i do not know where is the probleme.

this is my code for the image :

with self.canvas:
            self.bg = Rectangle(source='mahrez.jpg', pos=self.pos, size=self.size)

but instead of the image i want to use a video


回答1:


You can do what you want by using kivy.core.video and using that to set the texture of the Rectangle:

from kivy.core.video import Video as CoreVideo
.
.
.
    with self.canvas:
        self.bg = Rectangle(source='mahrez.jpg', pos=self.pos, size=self.size)
    self.video = CoreVideo()
    self.video.bind(on_frame=self.set_bg_texture)
    self.video.filename = 'BigBuckBunny.mp4'

    # just a delay to show that the original image is shown first
    Clock.schedule_once(self.start_vid, 3)

def start_vid(self, dt):
    self.video.play()

def set_bg_texture(self, *args):
    self.bg.texture = self.video.texture


来源:https://stackoverflow.com/questions/60485905/kivy-putting-video-inside-a-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!