python - 停止 kivy 视频

标签 python kivy kivy-language

我想在点击事件时停止这个 kivy 视频(默认播放)。我在树莓派上运行这个。这是我的 kv 和 python 代码。

<VideoScreen>:
name: 'Video'
BoxLayout:
    Video:
        id: 'video1'
        source: './media/Sequence_#1.mp4'
        state: root.current_video_state
        volume: 1
        options: {'eos': 'loop'}
        allow_stretch: True

视频循环播放,点击它切换到新屏幕“登录”,但视频不会停止并且仍在循环播放(我想在加载新屏幕后停止播放)。还有许多其他屏幕屏幕使用屏幕管理器连接到视频屏幕。假设加载屏幕工作正常。忽略缩进。

class VideoScreen(Screen):
    current_video_state = StringProperty()
    def __init__(self, **kwargs):
        super(VideoScreen,  self).__init__(**kwargs)
        self.bind(on_touch_down = self.on_stop)
        self.current_video_state = self.get_set_current_video_state()

    def get_set_current_video_state(self, *args):
        while(args):
            print('arg', args[0])
            if args[0] == 'pause':
            return 'pause'
        return 'play'

    def on_stop(self,  *args):
        self.state = 'pause'
        self.get_set_current_video_state('pause')
        self.parent.current = 'Login'

最佳答案

Video:
    # ...
    state: root.current_video_state

这部分将视频小部件的状态绑定(bind)到属性 current_video_state:每次 current_video_state 更改时,视频的状态将以​​相同的方式更改。您应该在(触摸)事件上更改此变量以暂停视频:

def on_stop(self,  *args):
    self.current_video_state = 'pause'  # this will change video state to 'pause'
    self.parent.current = 'Login'

关于python - 停止 kivy 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46601191/

相关文章:

python - Memcached 不允许缓存大于 1mb 限制的项目,即使它被覆盖

python - Pandas 根据不同的列对 NaN 进行插值

python - 有没有办法取消Kivy中的UrlRequest?

python - Kivy:使用一个切换按钮来更改另一个切换按钮的状态

python - Kivy标签代码从kivy语言转python

python - 减少 iPad 加速度计中的噪音

android - Kivy 中的 build.py 脚本编译错误

android - Python Buildozer PyMySQL 无法连接

Python/kivy - 类型错误 : 'kivy.properties.ObjectProperty' object is not iterable

Python-docx 提取的缺少单词的字符串