python - 如何使用 kivy v2.0.0 播放视频?
问题描述
我想用 Kivy 2.0.0 和 Python 3.6 播放视频,但运行此代码会给我一个加载错误,因为 Kivy 的视频播放器无法识别该文件。如何让 Kivy 的视频播放器识别文件?
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.videoplayer import VideoPlayer
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.video import Video
from kivy.lang.builder import *
from kivy.app import App
import kivy
import os
kivy.require('2.0.0')
# Main page code
class MainPage(Screen):
""" This is the code for the Main Screen """
# Initialization
def __init__(self, **var_args):
# Constructor for the Main Page class
super(MainPage, self).__init__(**var_args)
# Layout
self.layout = FloatLayout()
# Video player
self.filename = '/'
self.player = VideoPlayer(source=self.filename,state='play',options={'allow_stretch': True})
self.layout.add_widget(self.player)
# Add the layout to the screen
self.add_widget(self.layout)
# Main app class
class Video_Viewer(App):
""" Main build """
# Main build
def build(self, **kwargs):
# Create the screen manager
self.manager = ScreenManager()
# Add screens to screen manager
self.manager.add_widget(MainPage(name='Main'))
# Set the screen to the main sceren
self.manager.current = 'Main'
# Return the current screen of the screen manager
return self.manager
# Run the file
if __name__ == '__main__':
Video_Viewer().run()
这是由于代码而发生的错误:
[ERROR ] [Image ] Error loading <C:/Users/My Laptop/Downloads/video.mp4>
解决方案
尝试安装ffpyplayer
python -m pip install ffpyplayer
推荐阅读
- go - 如何在 Golang 中使用 gofpdi.importPage() 导入下载的空白 pdf 文件?
- python - 标准化不规则形状的数据(TypeError:只有 size-1 的数组可以转换为 Python 标量)
- python - 如何在熊猫系列中获得最接近零的 n 个值?
- node.js - Mongoose 删除带有 id 的双重嵌套对象
- laravel - 如何从关系中删除项目
- spring - 如何更新spring mongodb中的嵌入对象
- css - Vuetify:自定义样式中断分页
- django - 如何在 django 中永久更改主文件夹名称
- python - 使用 pathlib 模块关闭文件的推荐方法?
- java - CompletableFuture VS @Async