如何等待直到将YouTube视频嵌入pyqt5框架中

时间:2019-06-20 16:42:31

标签: pyqt5 pafy python-vlc

我正在使用pyqt5,适用于python和pafy的vlc制作媒体播放器,我尝试为YouTube视频获得最高分辨率,但是pafy给包含音频的视频提供了低分辨率,而没有高分辨率的视频却给了我音频,所以我尝试制作两个vlc实例并尝试同时运行它们。有时视频嵌入会花费很长时间,并且音频开始播放。是否有任何解决方案可以等到视频被嵌入并使视频与音频同时开始播放。还是您知道像pafy一样获得高分辨率和音频的YouTube流链接的方法吗?

############These are parts from code############
self.instance = vlc.Instance()
self.mediaplayer = self.instance.media_player_new()
self.mediaplayer2 = self.instance.media_player_new()
self.videoframe = QFrame()

def OnYT(self):
    url = "https://www.youtube.com/watch?v=7LnBvuzjpr4" #example
    video = pafy.new(url)
    best1 = video.getbestvideo()
    best2 = video.getbestaudio() 
    self.mediaplayer.set_mrl(best1.url)
    self.mediaplayer2.set_mrl(best2.url)

    if sys.platform.startswith('linux'):
        self.mediaplayer.set_xwindow(self.videoframe.winId())
    elif sys.platform == "win32":
        self.mediaplayer.set_hwnd(self.videoframe.winId())
    elif sys.platform == "darwin":
        self.mediaplayer.set_nsobject(int(self.videoframe.winId()))


    self.mediaplayer.play()
    self.mediaplayer2.play()

0 个答案:

没有答案