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

Kivy VideoPlayer fullscreen, loop, and hide controls

我刚开始使用 Kivy,所以如果我做错了什么请指出。我正在尝试使用视频播放器。也就是说,我似乎无法让它识别任何 "options",而且我真的很想要一种隐藏控件的方法(以防止用户使用 stopping/pausing/changing volume/interacting 等。而电影是运行宁)。

这是我目前得到的:

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()

eos: 'loop' 以上,好像完全忽略了。和 'fullscreen' 一样。双击播放器不会使其 运行 全屏显示。

我正在 Windows 上测试(但希望移植到 android),在后台 "console" window 中我有 2 个警告应该帮助我,但我想我不知道如何处理它:

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

理想情况下,我会在全屏模式下 运行 并且能够禁用控件(因此用户可以使用 keyboard/touch/timer events/etc 与事物交互)但是我找不到有关如何禁用它们的任何文档。有什么指点吗?

我已经设法让 window 本身在全屏模式下变为 运行,但我不认为这不是一回事。 谢谢!

我使用 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()

这是我为自己制作的示例,其中演示了其中的许多功能。它回答了你的问题。

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()