Kivy Stop视频并显示照片

时间:2019-02-26 01:21:01

标签: python kivy

我正在研究一个kivy框架(v1.10)。我正在尝试创建一个简单的照相亭软件,该软件可以运行视频循环并在有人单击屏幕时停止视频。之后,照相机拍摄照片,程序将其与两个按钮“是”或“否”一起显示在监视器上。他们将允许您重复照片。我正在为Raspberry PI开发此应用程序。我的问题是如何停止视频并制作其他内容。

好吧,所以,如果我想在第一部电影和按钮之间添加另一部电影,我是否必须添加一个新屏幕或更改此功能中的视频源self.bind(on_touch_down = self.on_stop)?我想添加一个带有倒计时时间的视频,然后让他通过拍照释放相机。然后使用按钮将这张照片显示一次:重复并继续。

from kivy.app import App
from kivy.logger import Logger
from kivy.uix.videoplayer import Video
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout



class Player(Video):
    def __init__(self,  **kwargs):
        super(Player,  self).__init__(**kwargs)
        self.source = './START.mp4'
        self.state='play'
        self.options={'eos': 'loop'}
        self.bind(on_touch_down = self.on_stop)
        self.get_set_current_video_state = self.get_set_current_video_state()

    def check(self):
        Logger.info("film position:" + str(self.position))

    def on_stop(self,  *args):
        print ('I have been clicked')
        Player.state='stop'
        #App.get_running_app().stop()
        #self.get_set_current_video_state = ('pause')
        return MyWindowApp().run()


class VideoPlayerApp(App):
    def build(self):
        return Player()

class MyWindowApp(App):

    def __init__(self):
        super(MyWindowApp, self).__init__()


        self.btn = Button(text='Push Me!')
        self.lbl = Label(text='Read Me!')

1 个答案:

答案 0 :(得分:1)

不要尝试使用两个Apps,而要使用两个Screens。这是使用Screens对代码的修改:

from kivy.app import App
from kivy.logger import Logger
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.video import Video
from kivy.uix.label import Label
from kivy.uix.button import Button



class Player(Video):
    def __init__(self,  **kwargs):
        super(Player,  self).__init__(**kwargs)
        self.source = './START.mp4'
        self.state='play'
        self.options={'eos': 'loop'}
        self.bind(on_touch_down = self.on_stop)

    def check(self):
        Logger.info("film position:" + str(self.position))

    def on_stop(self,  *args):
        print ('I have been clicked')
        self.state='stop'  # stop the video
        sm.current = 'WindowApp'  # switch to the other Screen


class MyWindowApp(Screen):

    def __init__(self, **kwargs):
        super(MyWindowApp, self).__init__(**kwargs)


        self.btn = Button(text='Push Me!', pos_hint={'center_x': 0.5, 'center_y': 0.75}, size_hint=(0.2, 0.2))
        self.lbl = Label(text='Read Me!', pos_hint={'center_x': 0.5, 'center_y': 0.25})

        self.add_widget(self.btn)
        self.add_widget(self.lbl)

sm = ScreenManager()
screen1 = Screen(name='video')
screen1.add_widget(Player())
sm.add_widget(screen1)
screen2 = MyWindowApp(name='WindowApp')
sm.add_widget(screen2)

class VideoPlayerApp(App):
    def build(self):
        return sm


VideoPlayerApp().run()

我已将您的导入更正为from kivy.uix.video import Video