2

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

And I call it like this:

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

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.

2
  • I think the problem is that the VLC player uses the youtube.lua script to find the true location of the video and then passes this to the player. I will simply need to do that myself somehow. Commented Jul 12, 2012 at 15:54
  • And here is Fixed VLC youtube.lua parser at Github. Commented Jul 7, 2013 at 18:25

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

I had the same problem recently but the youtube.lua file seems to have been long fixed.

Thanks to a tip from Rémi Denis-Courmont, one of the VLC developers, I solved this problem by creating a MediaListPlayer and then adding the media (local file or YouTube URL) to the MediaList then associating that to the player. I am not sure why such a convoluted approach is needed, but at least it works for me.

   #movie is the YouTube or a local URL
   media = instance.media_new(movie)
   media_list = instance.media_list_new([movie]) #A list of one movie

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

   #Create a new MediaListPlayer instance and associate the player and playlist with it

   list_player =  instance.media_list_player_new()
   list_player.set_media_player(player)
   list_player.set_media_list(media_list)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.