Kivy Video Player is not working on Raspberry 3B+

2019-09-24 21:35发布

问题:

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.

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

Output logs:

[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.

回答1:

I tried a long time and therefore feel comfortable saying, there is no way to use the standard kivy videoplayer on a 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.

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

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')