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

Python 播放视频后如何更改kivy中的当前屏幕,python,kivy,Python,Kivy,我的应用程序有一个按钮>点击按钮将开始播放视频>视频结束后,我想导航到最终屏幕 #!/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

我的应用程序有一个按钮>点击按钮将开始播放视频>视频结束后,我想导航到最终屏幕

#!/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()
#/usr/bin/kivy
进口克维
kivy.require('1.7.2')
从kivy.app导入应用程序
从kivy.lang导入生成器
从kivy.uix.screenmanager导入screenmanager,屏幕
从kivy.uix.gridlayout导入gridlayout
从kivy.uix.button导入按钮
导入网络浏览器
从kivy.uix.videoplayer导入videoplayer
导入时间
Builder.load_字符串(“”)
:
网格布局:
填充:5
间距:5
科尔斯:1
填充:根。宽度*0.1
按钮:
背景\u正常:“”
背景颜色:(0.862,0.078,0.235,0.9)
文字:“播放”
字体大小:“20sp”
按:root.manager.current='vdo'
on_press:root.val1()
:
网格布局:
科尔斯:1
视频播放器:
id:睾丸
声明:“停止”
资料来源:'http://techslides.com/demos/sample-videos/small.webm'
全屏:正确
图像_播放:“black.png”
图片_stop:'black.png'
图片_暂停:“black.png”
图片_volumehigh:'black.png'
下图:“black.png”
图片_volumemedium:'black.png'
图片_volumemuted:'black.png'
:
网格布局:
科尔斯:1
标签:
文字:“结束”
''')
类菜单屏幕(屏幕):
def val1(自身):
打印“1已执行”
vdo.ids.testid.state='play'
sm.current='final'
Vdo类(屏幕):
def val2(自身):
打印“我被处决”
期末考试(屏幕):
def val3(自身):
打印“我被处决”
sm=屏幕管理器()
menu=MenuScreen(name='menu')
sm.add_小部件(菜单)
vdo=vdo(名称='vdo')
sm.add_小部件(vdo)
final=final(name='final')
sm.add_小部件(最终版)
类主应用程序(应用程序):
def生成(自):
返回sm
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
MainApp().run()

视频结束后,我的代码不会移动到最终屏幕。我尝试在视频播放后给予时间睡眠,但在此期间视频将在后台播放。

我将尝试将函数绑定到VideoPlayer状态属性,以便在触发时检查位置==持续时间(结束)并移动到下一屏幕

<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'
我希望这会有所帮助

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