Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New playback of another video file in PyQT5 using VLC #249

Open
Tadont opened this issue Feb 13, 2023 · 0 comments
Open

New playback of another video file in PyQT5 using VLC #249

Tadont opened this issue Feb 13, 2023 · 0 comments

Comments

@Tadont
Copy link

Tadont commented Feb 13, 2023

Good afternoon everyone, I am writing a script that, when launched, plays a video by its number. Then, after the end of playback, the script asks for the video number for the next playback, and so on.

`
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(['--video-on-top'])
    self.instance.log_unset()
    
    self.media=None
    
    self.mediaplayer = self.instance.media_player_new()
    
    self.create_ui()
    self.open_file()
def create_ui(self):
    
  
    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)
    lay = QtWidgets.QVBoxLayout(central_widget)
    lay.addWidget(self.videoframe)
    
def play(self):
    if self.mediaplayer.play() == -1:
       self.open_file()
    self.mediaplayer.play()

def open_file(self):
    numberfile = input("File number: ")
    filename = (f"/home/Tadont/Video/{numberfile}.mp4")
    self.media = self.instance.media_new(filename)
    self.mediaplayer.set_media(self.media)
    self.eventManager=self.mediaplayer.event_manager()
    self.eventManager.event_attach(vlc.EventType.MediaPlayerEndReached, self.next_file)
    self.play()
    
  
def next_file(self, event):
     if event.type == vlc.EventType.MediaPlayerEndReached:
         #self.mediaplayer.stop()
         self.open_file()

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":
main()`

I have the first file to play, then I write the file number for the second playback, but the second file does not start. How to solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant