简体   繁体   English

播放视频后如何在kivy中更改当前屏幕

[英]How to change current screen in kivy after playing video

My app have a button>click on button will start playing a video>after video finishes, i want to navgate to final screen. 我的应用程序有一个按钮>单击按钮将开始播放视频>视频结束后,我想导航到最终屏幕。

#!/usr/bin/kivy
import kivy
kivy.require('1.7.2')

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
import webbrowser
from kivy.uix.videoplayer import VideoPlayer
import time

Builder.load_string('''
<MenuScreen>:
    GridLayout:
        padding: 5
        spacing: 5
        cols: 1
        padding: root.width*0.1
        Button:
            background_normal: ''
            background_color:(0.862, 0.078, 0.235, 0.9)
            text: 'PLAY'
            font_size: '20sp'
            on_press: root.manager.current='vdo'
            on_press: root.val1()
<Vdo>:
    GridLayout:
        cols: 1
        VideoPlayer:
            id: testid
            state: 'stop'
            source: 'http://techslides.com/demos/sample-videos/small.webm'
            fullscreen: True
            image_play: 'black.png'
            image_stop: 'black.png'
            image_pause: 'black.png'
            image_volumehigh: 'black.png'
            image_volumelow: 'black.png'
            image_volumemedium: 'black.png'
            image_volumemuted: 'black.png'
<Final>:
    GridLayout:
        cols: 1
        Label:
            text: 'over'

''')

class MenuScreen(Screen):
    def val1(self):
        print "1 is executed"
        vdo.ids.testid.state='play'
        sm.current='final'

class Vdo(Screen):
    def val2(self):
        print "i am executed"

class Final(Screen):
    def val3(self):
        print "i am executed"

sm = ScreenManager()
menu = MenuScreen(name='menu')
sm.add_widget(menu)
vdo = Vdo(name='vdo')
sm.add_widget(vdo)
final = Final(name='final')
sm.add_widget(final)

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

if __name__ == '__main__':
    MainApp().run()

My code do not move to final screen after video finishes. 视频播放完后,我的代码未移至最终屏幕。 I tried give time sleep after video play but during that time video will play in background. 我尝试在视频播放后让时间入睡,但在这段时间内,视频将在后台播放。

I would try to bind a function to the VideoPlayer state property so that when is fire you will check if position==duration (the end) and move to the next screen 我会尝试将一个函数绑定到VideoPlayer状态属性,以便在发生火灾时,您将检查position == duration(结束)并移至下一个屏幕

<Vdo>:
    video: testid #easier to access this way
    VideoPlayer:
        id: testid
        state: 'stop'
        source: 'http://techslides.com/demos/sample-videos/small.webm'
        fullscreen: True
        image_play: 'black.png'
        image_stop: 'black.png'
        image_pause: 'black.png'
        image_volumehigh: 'black.png'
        image_volumelow: 'black.png'
        image_volumemedium: 'black.png'
        image_volumemuted: 'black.png'

in your python code: 在您的python代码中:

def state_change(instance, value):
    if vdo.video.duration == vdo.video.position:
        sm.current = 'final'
vdo.video.state.bind(state_change)

I hope this will help 我希望这个能帮上忙

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM