【问题标题】:Stopping a kivy video停止 kivy 视频
【发布时间】:2017-10-06 08:10:08
【问题描述】:

我想在点击事件时停止这个 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'

【问题讨论】:

  • 视频小部件在树莓派上是否适合您?我无法让它工作,我认为很多其他人也有同样的问题。我们使用了像gist.github.com/natcl/005dc4c6434ed7b5a59a 这样的解决方法。你有没有做任何具体的事情来让它在树莓派上工作?

标签: python kivy kivy-language


【解决方案1】:
Video:
    # ...
    state: root.current_video_state

这部分将视频小部件的状态绑定到属性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'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-04
    • 2012-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 2012-08-04
    相关资源
    最近更新 更多