Search code examples
pythonkivykivy-languagevideo-player

VideoPlayer error loading video only plays sound - Warning: Removing channel layout 0x3, redundant with 2 channels


I am trying to use VideoPlayer to load a local video. The program runs fine when it is standalone (in its own file). But, when I bring it into my main program, it loads the video but only plays the sound. I get an error (warning, to be more precise) message:

[WARNING] [ffpyplayer ] [ffpyplayer_abuffersink @ 000001e84fb55580] Removing channel layout 0x3, redundant with 2 channels

Here's the standalone version:

import cv2
from kivy.uix.videoplayer import VideoPlayer
from kivymd.app import MDApp


class PlayVid(MDApp):

    def build(self):
        player = VideoPlayer(source="Roadhouse.mp4")
        player.state = "play"
        player.options = {"eos": "stop"}
        player.allow_stretch = True

        return player


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

And here is the same thing split in functions and class in my main program:

class PlayVid(MDApp):

    def playnow(self):
        # player = VideoPlayer(source='Roadhouse.mp4')
        # player.state = "play"
        video = VideoPlayer(source='Roadhouse.mp4')
        video.state = "play"
        # player.options = {"eos": "stop"}
        # player.allow_stretch = True
        return video


class SecondWindow(Screen):
    def build (self):
        sm = ScreenManager()

        self.sec_screen = SecondWindow()

        sm.add_widget(self.sec_screen)

        return sm

    def start_play(self):

        PlayVid.playnow(self)

A kv button in SecondWindow triggers start_play and then PlayVid.playnow(self). That's all. It runs, loads the file, and then just plays the sound. No video.

I can't understand what I'm doing wrong. Help?

Thanks!

I created a standalone program for it, and it works. I just can't understand why it drops the video and plays the sound when brought into the main program.


Solution

  • Your playnow() method returns the VideoPlayer widget, but that return is ignored. You must add that widget to your GUI in order to see it. Try using this version of start_play():

    def start_play(self):
    
        v = MDApp.get_running_app().playnow()
        self.add_widget(v)