【问题标题】:Kivy stop Video and show photoKivy 停止视频并显示照片
【发布时间】:2019-03-10 04:10:08
【问题描述】:

我正在开发一个 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!')

【问题讨论】:

  • 考虑VideoPlayer.state = 'stop',如Video Player中所述。
  • 此命令关闭了我的应用程序,但我如何才能停止视频并运行其他活动。例如带有照片背景的菜单,带有两个按钮是或否。
  • 文档没有说它会关闭应用程序。试试pause 而不是stop
  • Stopping a kivy video的可能重复

标签: python kivy


【解决方案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

【讨论】:

  • 好的,所以如果我想在第一个和按钮之间添加另一部电影,我是否必须添加一个新屏幕或者在这个函数中更改视频源 self.bind (on_touch_down = self. on_stop)?我想加个倒计时的视频,让他通过拍照来释放相机。然后使用按钮显示此照片一次:重复并继续。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多