使用 python-vlc 切换 VLC 屏幕

问题描述 投票:0回答:1

我正在使用 python-vlc 运行多个实时流。

所以像这样:

stream1 = vlc.MediaPlayer("rtsp://...")
stream2 = vlc.MediaPlayer("rtsp://...")
stream1.play()
stream1.audio_toggle_mute()
stream2.play()
stream2.toggle_fullscreen()

我可以使用toggle_fullscreen来显示一个流,但是如何在多个流之间切换并将特定流带到前台?我是否必须停下来重新开始,还是有更简单的方法?

python vlc python-vlc
1个回答
0
投票

我最终使用 PyQt5 创建一个窗口并在其中嵌入 vlc 媒体播放器,然后使用它进行切换。我用来定义流的代码是:


class Stream(QtWidgets.QMainWindow):

    def __init__(self, url: str, title: str, parent=None):
        super(Stream, self).__init__(parent)
        self.setWindowTitle(title)

        # creating a basic vlc instance
        self.instance = vlc.Instance()
        self.media_player = self.instance.media_player_new()
        self.video_frame = QtWidgets.QFrame()

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

        central_widget = QtWidgets.QWidget()
        self.setCentralWidget(central_widget)
        lay = QtWidgets.QVBoxLayout(central_widget)
        lay.addWidget(self.video_frame)
        self.video_frame.setStyleSheet("border: 0px")
        central_widget.setStyleSheet("border: 0px")
        self.setStyleSheet("border: 0px")

        youtube_url = pafy.new(url).getbest()
        media = self.instance.media_new(youtube_url.url)
        self.media_player.set_media(media)
        self.media_player.audio_set_volume(0)
        self.media_player.play()
        self.showFullScreen()

    def bring_to_foreground(self):
        self.window().activateWindow()
        self.media_player.audio_set_volume(100)

    def mute(self):
        self.media_player.audio_set_volume(0)
© www.soinside.com 2019 - 2024. All rights reserved.