Kivy VideoPlayer全屏,循环和隐藏控件

时间:2015-04-26 11:53:32

标签: python kivy

我刚开始与Kivy合作,所以请指出我做错了什么......我正在尝试使用视频播放器。也就是说,我似乎无法识别任何“选项”,我真的想要一种隐藏控件的方法(以防止用户停止/暂停/改变音量/交互等等。而电影是运行)。

这是我到目前为止所得到的:

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.videoplayer import VideoPlayer

class MyApp(App):
    def build(self):
        self.player = VideoPlayer(fullscreen=True, allow_fullscreen=True, source='mymovie.mp4', state='play', options={'allow_stretch': True, 'eos': 'loop', 'fullscreen': True})
        return(self.player)


if __name__ == '__main__':
    MyApp().run()
上面的'循环',似乎完全被忽略了。就像'全屏'一样。双击播放器不会使其以全屏模式运行。

我在Windows上测试(但希望移植到android),并且在后台的“控制台”窗口中我有2个警告可以帮助我,但我想我不知道怎么知道如何照顾它:

[WARNING           ] [VideoPlayer ] Cannot switch to fullscreen, window not found.
[WARNING           ] [VideoPlayer ] Cannot switch to fullscreen, window not found.

理想情况下,我会让它在全屏运行并且能够禁用控件(因此用户可以使用键盘/触摸/计时器事件等进行交互)但我找不到任何关于如何使用的文档禁用它们。有什么指针吗?

我设法让窗口本身全屏运行,但这不是一回事,我不这么认为。 谢谢!

2 个答案:

答案 0 :(得分:4)

我使用kivy.uix.video.Video代替kivy.uix.videoplayer.VideoPlayer解决了我的问题。我不知道这是不是我最初应该做的事情(刚刚开始!),但为了防止其他人遇到这个问题,这对我有用:

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.video import Video

class MyApp(App):
    def build(self):
        video = Video(source='mymovie.mp4')
        video.state='play'
        video.options = {'eos': 'loop'}
        video.allow_stretch=True
        return video

if __name__ == '__main__':
    MyApp().run()

答案 1 :(得分:1)

这是我为自己做的一个例子,展示了许多这些功能。它回答了您的问题。

import kivy
kivy.require('1.9.0')
import time
import os
import sys
import psutil
import logging

from kivy.app import App
from kivy.uix.video import Video
from kivy.config import Config
from kivy.core.window import Window
Config.set('graphics', 'position', 'custom')
Config.set('graphics', 'left', 0)
Config.set('graphics', 'top',  500)
Config.set('graphics', 'resizable', 'False')
#Config.set('graphics', 'borderless',  1)
Config.set('graphics', 'width', 1127)
Config.set('graphics', 'height', 636)

class MyApp(App):

    video = None
    def build(self):
        Window.bind(on_keyboard=self.on_keyboard)  # bind our handler
        self.video = Video(source='C:\\drop.mp4')
        self.video.state='play'
        #self.video.options = {'eos': 'loop'}
        self.video.allow_stretch=True
        self.video.pos_hint = {'top': 1.0}
        self.video.bind(eos=self.VideoDone)
        return self.video

    def VideoDone(self, value, value2):
        print ("video done", value, value2)

    def on_stop(self):
        # The Kivy event loop is about to stop, set a stop signal;
        # otherwise the app window will close, but the Python process will
        # keep running until all secondary threads exit.
        print ('stopping and closing kivy')
        #self.video.state='stop'


    def on_keyboard(self, window, key, scancode, codepoint, modifier):
        print (window, key, scancode, codepoint, modifier)
        if codepoint == 'p':
            print ('pausing with p pressed')
            self.video.state='stop'
        if codepoint == 's':
            print ('starting with s pressed')
            self.video.state='play'
        if codepoint == 'r':
            print ('re-starting with r pressed')
            self.video.seek(0, precise=True)




if __name__ == '__main__':
    print ("hi")
    MyApp().run()