VLC Python 不播放 YouTube 视频 [英] VLC Python doesn't play YouTube video

查看:47
本文介绍了VLC Python 不播放 YouTube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试通过 Python 绑定使用 VLC 媒体播放器播放 YouTube URL 时,视频实际上并没有播放.

When trying to play a YouTube URL with VLC media player via the Python bindings, the video does not actually play.

这是我的代码,用于播放:

Here is my code which does the playing:

    def play(self, mrl):

    self.instance = vlc.Instance()

    try:
        self.media = self.instance.media_new_location(mrl)
    except NameError:
        print('NameError: %s (%s vs LibVLC %s)' % (sys.exc_info()[1],
                                                   vlc.__version__,
                                                   vlc.libvlc_get_version()))

    self.player = self.instance.media_player_new()
    self.player.set_media(self.media)

    event_manager = self.player.event_manager()
    event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, self.end_callback)

    self.player.play()

    while self.stillPlaying:
        #do nothing
        pass

我这样称呼它:

    play("http://www.youtube.com/watch?v=2hP-UGqA1Ek")

如果您确实使用 VLC 媒体播放器播放这种类型的链接,它会找到"视频并播放它.但是我的代码发生的所有事情都是针对页面的标准 HTTP GET,以及从 YouTube 返回页面内容,但没有视频.

If you do use VLC media player to play this type of link, it will 'find' the video and play it. But all that happens with my code is a standard HTTP GET for the page, and a return of the page content from YouTube, but no video.

推荐答案

那是因为您提供的链接不是视频的链接.VLC 媒体播放器可以获得 YouTube 视频的实际链接,但 libVLC 不会这样做.

That's because the link you provided is NOT the link to the video. VLC media player can get the actual link to the YouTube video, but libVLC will not do this.

这篇关于VLC Python 不播放 YouTube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆