Kivy 视频播放器不适用于 Raspberry 3B+ [英] Kivy Video Player is not working on Raspberry 3B+

查看:11
本文介绍了Kivy 视频播放器不适用于 Raspberry 3B+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的 RPI3+ 上安装了 Rasbian Stretch 和 Kivy.我的应用程序正常工作,只是没有播放视频.Rasbian、kivy 和 gstreamer 是最新的.我的应用程序和视频在 KivyPie 0.9b 上运行没有任何问题.

I just installed Rasbian Stretch and Kivy on my RPI3+. My application work properly just videos are not playing. Rasbian, kivy and gstreamer are up to date. My application and video were working on KivyPie 0.9b without any problem.

kivy 是否有任何手动安装 Rasbian 时播放视频的配置?

Does kivy has any config for video playing on manual installation of Rasbian?

输出日志:

[INFO] [MTD] 旋转设置为 0
[警告] [图片] 无法加载图片
[错误] [图像] 加载纹理时出错 ./data/images/welcome.mp4
[错误] [VideoGstplayer] GStreamer 遇到一般支持库错误.
[错误] [VideoGstplayer] GStreamer 遇到一般支持库错误.
[ERROR ] [VideoGstplayer] 内部数据流错误.

[INFO ] [MTD ] rotation set to 0
[WARNING] [Image ] Unable to load image
[ERROR ] [Image ] Error loading texture ./data/images/welcome.mp4
[ERROR ] [VideoGstplayer] GStreamer encountered a general supporting library error.
[ERROR ] [VideoGstplayer] GStreamer encountered a general supporting library error.
[ERROR ] [VideoGstplayer] Internal data stream error.

推荐答案

我尝试了很长时间,因此很舒服地说,没有办法在树莓派上使用标准的 kivy 视频播放器.

I tried a long time and therefore feel comfortable saying, there is no way to use the standard kivy videoplayer on a raspberry pi.

另一种方法是使用 OMXPlayer.我为 OMXPlayer 使用了以下包装器https://github.com/willprice/python-omxplayer-wrapper也许首先尝试让 OMXPlayer 在 Raspberry Pi 上工作.

The alternative is to use OMXPlayer. I used the following wrapper for OMXPlayer https://github.com/willprice/python-omxplayer-wrapper maybe try first to get OMXPlayer on the Raspberry Pi working.

这是我在树莓派上使用 kivy gui 时编写的用于观看视频的旧脚本

That's an old script I wrote to view a video while using a kivy gui on raspberry pi

我希望它有所帮助,您可以将其视为寻找自己解决方案的灵感

I hope it helps and you can see it as an inspiration for finding your own solution

主要逻辑是将OMXPlayer放在后台,让kivy透明.见 clearbckgrnd

Main logic is to put OMXPlayer in the background and make kivy see-through. see clearbckgrnd

import subprocess
import os


from time import sleep

# https://github.com/willprice/python-omxplayer-wrapper
from omxplayer.player import OMXPlayer

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen
from kivy.lang import Builder
from kivy.properties import ObjectProperty, BooleanProperty

from kivy.core.window import Window

from kivy.clock import Clock



class VideoPlayerScreen(Screen):
    slider = ObjectProperty()
    minimized = BooleanProperty(False)

    @staticmethod
    def clearbckgrnd():
        Window.clearcolor = (0,0,0,0)

    @staticmethod
    def addbckgrnd():
        Window.clearcolor = (0,0,0,1)

    def play(self):
        self.player = OMXPlayer('/home/pi/voice-recognizer-raspi/GUI/test.mp4')
        self.player.set_video_pos(0,0,800,480)
        #self.player.hide_video()
        #self.player.show_video()
        self.set_slider()
        Clock.schedule_once(self.quit, 20)
        Clock.schedule_interval(self.set_slider, 3)


    def playpause(self):
        self.player.play_pause()

    def quit(self, gg, **kwargs):
        self.player.quit()
        App.get_running_app().stop()


    def set_slider(self, *args):
        pos = self.player.position() # in seconds as int
        duration =  self.player.duration() # in seconds as float
        #return pos/duration
        self.slider.value_normalized = pos/duration
        #return 0.5

    def set_videopos(self, *args):
        pos = self.player.position() # in seconds as int
        duration =  self.player.duration() # in seconds as float
        if abs (pos/duration - self.slider.value_normalized) > 0.05:
            self.player.set_position(self.slider.value_normalized*duration)


    def change_size(self):
        #width 800
        #height 480
        if not self.minimized:
            self.player.set_video_pos(2,2,798,418)




class VideoApp(App):
    def build(self):
        return Builder.load_string('''
ScreenManager:
    Screen:
        Button:
            on_press: root.current = "video"
            on_press: self.enabled= False
    VideoPlayerScreen:

<VideoPlayerScreen>:
    slider: slider
    name: "video"
    on_enter: self.clearbckgrnd()
    on_enter: self.play()
    on_pre_leave: self.addbckgrnd()
    BoxLayout:
        orientation: 'vertical'
        Button:
            size_hint_y: 420
            #text: "play"
            on_press: print('button to minimize pressed')
            on_press: root.change_size()
            background_color: (0,0,0,1)
            Image:
                source: './Infinity.gif'
                height: self.parent.height / 1.5 
                y: self.parent.y + self.parent.height /2 - self.height / 2
                x: self.parent.x + self.parent.width / 2 - self.width / 2
                allow_stretch: False
        BoxLayout:
            orientation: 'vertical'
            size_hint_y: 60
            Slider:
                id: slider
                on_value: root.set_videopos(self.value_normalized)
                #value_normalized: root.set_slider
            BoxLayout:
                Button:
                    text: 'Play/Pause'
                    on_press: root.playpause()

''')

if __name__ == "__main__":
    video = VideoApp()
    try:
        video.run()
    except KeyboardInterrupt:
        video.stop()
        os.system('killall dbus-daemon')

这篇关于Kivy 视频播放器不适用于 Raspberry 3B+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆