0

I've been working with python for a while. I am writing a script in which the VLС media player should be launched in a PyQT5. The media player starts the video by the number entered in the terminal. After playing the video, the media player waits for the number to be written to the terminal to play the next file. I will be grateful for any help.

import sys
import time
import vlc

from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import Qt


class Player(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(Player, self).__init__(parent)
        #self.setWindowTitle("Media Player")
        # creating a basic vlc instance
        self.instance = vlc.Instance()
        self.instance.log_unset()
        
        self.mediaplayer = self.instance.media_player_new()
        ##########video frame
        self.videoframe = QtWidgets.QFrame(
            frameShape=QtWidgets.QFrame.Box, frameShadow=QtWidgets.QFrame.Raised
        )

        if sys.platform.startswith("linux"):  # for Linux using the X Server
            self.mediaplayer.set_xwindow(self.videoframe.winId())
        elif sys.platform == "win32":  # for Windows
            self.mediaplayer.set_hwnd(self.videoframe.winId())
        elif sys.platform == "darwin":  # for MacOS
            self.mediaplayer.set_nsobject(self.videoframe.winId())

        central_widget = QtWidgets.QWidget()
        self.setCentralWidget(central_widget)
        self.setWindowFlags(Qt.FramelessWindowHint)
        #self.setWindowState(Qt.WindowFullScreen)
        lay = QtWidgets.QVBoxLayout(central_widget)
        lay.addWidget(self.videoframe)
        

        filename = (f"/home/neuro/Видео/fluger/лопасти/{numberfile}.mp4")
        media = self.instance.media_new(filename)
        self.mediaplayer.set_media(media)
        
        self.mediaplayer.play()
        #time.sleep(10)
        #self.mediaplayer.stop()
        

def main():
 app = QtWidgets.QApplication(sys.argv)
 player = Player() 
 player.show()
 player.move(1, 1)
 player.resize(406, 86)
 player.setObjectName("MainWindow")
 player.setStyleSheet("#MainWindow{background-color:black}")
 sys.exit(app.exec_())
 
    
if __name__ == "__main__":
 while True:    
    

    
    numberfile = input("Номер файла: ")
    main()

I understand that there should be a cycle. but how to implement it so that after the first playback it re-requests the number for the next playback?

musicamante
  • 41,230
  • 6
  • 33
  • 58
Tadont
  • 11
  • 2
  • There should be no cycle, nor any attempt to block like `time.sleep()`. Look for callback usage in the VLC (not VLS) documentation. – musicamante Feb 06 '23 at 21:22

0 Answers0