1

I'm developing a screen for an application that will loop a video until there is a touch event on the screen. The event to detect the touch is working, but the video only runs once and then goes to black screen. I'm developing in python, on windows the application makes the video loop correctly but when I migrate to the raspberry pi 4 environment, the video is only played once. I would like to understand if there is something I am missing, some library, some incorrectly applied function...

Here's code:

class Video_Screen(QWidget):
    
    def change_first_screen(self):
        thread.screen.emit(1)

    def __init__(self,parent=None):

        super(QWidget,self).__init__(parent)
        filename = ""
        if(os.environ['SYSTEM'] == "RASPBIAN"):
            filename = diretorio+'/RaspberryPi/'+os.environ['VIDEO_FILENAME']
        else:
            filename = diretorio+'\\RaspberryPi\\'+os.environ['VIDEO_FILENAME'].replace('/','\\')
        
        self.playlist = QMediaPlaylist()

        self.playlist.addMedia(QMediaContent(QUrl.fromLocalFile(filename)))
        self.playlist.setPlaybackMode(QMediaPlaylist.PlaybackMode.Loop)

        self.mediaPlayer = QMediaPlayer()
        self.mediaPlayer.setPlaylist(self.playlist)
    
        videoWidget = QVideoWidget()
    
        self.mediaPlayer.setVideoOutput(videoWidget)

        self.mediaPlayer.play()

        main = QVBoxLayout()
        main.addStretch(1)
        main.addWidget(videoWidget)
        main.addStretch(1)
        self.setLayout(main)
        
    def mousePressEvent(self, event):
        self.change_first_screen()

The following libraries are installed on the raspberry pi:

sudo apt-get install libqt5multimedia5-plugins python3-pyqt5.qtmultimedia python3-pip python3-pyqt5 -y

I tried a few different approaches like detecting when the video ends and setting the position to 0, or signal detecting when the video ends to trigger play again, but nothing worked.

Expectation is to get the video running in loop, the video is in .avi format.

  • This question didn't help me despite of facing a similar problem [link](https://stackoverflow.com/questions/67090531/pyqt-playing-video-repeat-endlessusing-qmediaplayer-qmediaplaylist) – Gabriel Bastos Feb 08 '23 at 16:20

0 Answers0