How to give youtube url

This forum is about all development around libVLC.
hkMen
New Cone
New Cone
Posts: 3
Joined: 07 Jul 2010 09:09

How to give youtube url

Postby hkMen » 07 Jul 2010 09:18

Hi all,
I am developing an application in C using libvlc to play youtube videos. I used this api call libvlc_media_new_path to set the url. But it doesn't works. It works if I give a local path and also works when giving url using vlc GUI. Is there any other calls or anything to configure for playing network streamed videos.
Following is my sample code

int main(int argc, char **argv) {
const char * const vlc_args[] = {
"-I", "dumy", // No special interface
"--ignore-config", // Don't use VLC's config
"--plugin-path=./plugins",
"--reset-plugins-cache"
};
libvlc_media_t* m_pMedia;
libvlc_instance_t* m_pVLCInstance = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
libvlc_media_player_t* m_pMediaPlayer = libvlc_media_player_new(m_pVLCInstance);
m_pMedia = libvlc_media_new_path(m_pVLCInstance, "http://www.youtube.com/watch?v=_lP0CmEA6PA&fmt=18");
libvlc_media_player_set_media (m_pMediaPlayer, m_pMedia);
libvlc_media_player_play (m_pMediaPlayer);

Thanks in advance
HK

ivoire
Cone that earned his stripes
Cone that earned his stripes
Posts: 413
Joined: 20 Aug 2008 11:29
VLC version: trunk
Operating System: linux (debian sid)
Contact:

Re: How to give youtube url

Postby ivoire » 07 Jul 2010 10:41

AFAIK you must:
When the media is played, the script that arse the youtube webpage create one subitem which contains the vidéo. Take this subitem and play it, it will be the youtube vidéo.

hkMen
New Cone
New Cone
Posts: 3
Joined: 07 Jul 2010 09:09

Re: How to give youtube url

Postby hkMen » 07 Jul 2010 15:32

Hi,
Thanks for the reply. But can you be more specific answer(I am a newbie to libvlc development) .
What you mean by the "script that parse the youtube webpage"?

HK

ivoire
Cone that earned his stripes
Cone that earned his stripes
Posts: 413
Joined: 20 Aug 2008 11:29
VLC version: trunk
Operating System: linux (debian sid)
Contact:

Re: How to give youtube url

Postby ivoire » 07 Jul 2010 15:34

The youtube page is just a webpage, so VLC must parse the webpage to find the url of the video. This url is then added as a subtime of the current media. So have a look at the subitem of the media (after it was played) and you might find a subitem that contains the youtube video.

hkMen
New Cone
New Cone
Posts: 3
Joined: 07 Jul 2010 09:09

Re: How to give youtube url

Postby hkMen » 07 Jul 2010 16:06

So what you mean is by getting the url using libvlc_media_get_meta call?

ivoire
Cone that earned his stripes
Cone that earned his stripes
Posts: 413
Joined: 20 Aug 2008 11:29
VLC version: trunk
Operating System: linux (debian sid)
Contact:

Re: How to give youtube url

Postby ivoire » 07 Jul 2010 16:13

Use libvlc_media_subitems when the media has finished to play.

joeystyles
New Cone
New Cone
Posts: 1
Joined: 18 Aug 2010 21:51
VLC version: 1.1.2
Operating System: Windows Vista

Re: How to give youtube url

Postby joeystyles » 18 Aug 2010 22:20

I am having the same problem. I was wondering if you ever solved this.

I tried calling libvlc_media_subitems after libvlc_media_player_play but the list was empty. Not sure what I am doing wrong.

Here is a snippet of my code:

Code: Select all

m_VLCMedia = libvlc_media_new_location(m_VLCEngine, "http://www.youtube.com/watch?v=lB95KLmpLR4"); if (m_VLCMedia) { /* Create a media player playing environment */ libvlc_media_player_set_media(m_VLCMediaPlayer, m_VLCMedia); /* Play the media_player */ libvlc_media_player_play(m_VLCMediaPlayer); libvlc_media_list_t *m_VLCMediaList = libvlc_media_subitems(m_VLCMedia); if (m_VLCMediaList) { // never get here... } }

Diamonddrake
Blank Cone
Blank Cone
Posts: 18
Joined: 17 Oct 2010 05:04

Re: How to give youtube url

Postby Diamonddrake » 11 Nov 2010 21:10

I am also wondering if you ever solved this. I am trying to do the same. if anyone has any insight, please post back.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: How to give youtube url

Postby sherington » 22 Nov 2010 12:46

I am also wondering if you ever solved this. I am trying to do the same. if anyone has any insight, please post back.
Here's what works for me:

1. Play a YouTube URL as you would any other (libvlc_media_new_path, libvlc_media_player_play, etc)
2. Wait via events for playback started
3. Wait via events for playback completed <-- this is important
4. Get the sub-items (libvlc_media_subitems)
5. Get the first sub-item (libvlc_media_list_lock, libvlc_media_list_item_at_index, libvlc_media_list_unlock)
6. Set the sub-item on the media player (libvlc_media_player_set_media)
7. Play the sub-item (libvlc_media_player_play)
8. Release the sub-item list (libvlc_media_list_release)

If you don't wait properly at steps 2 and 3 then you will be getting the sub-items too early (they won't exist and you will get NULL returned at step 4).

Instead of waiting for events you could poll the media player state and/or sleep for a bit (this is not the 'right' way but if you're just hacking up something to test it's very simple).

The other thing is to make sure that your application/libvlc can see the LUA scripts. If you use your Linux distribution VLC package this most likely will not be a problem for you, but if you do your own vlc builds I had to create a symlink like this to point to the right place:

Code: Select all

$cd ~/.local/share/vlc $ln -s /home/linux/vlc-1.1/share/lua
I do not know to how to force libvlc to look for the scripts in a particular directory (via libvlc args for example).

I have this working with the Java bindings, but what I probably need to do is to come up with some robust and generic way to handle media with sub-items - at the moment this is unfortunately only handled as a special case for YouTube URLs.

Prashanth
New Cone
New Cone
Posts: 1
Joined: 06 Dec 2010 22:42

Re: How to give youtube url

Postby Prashanth » 06 Dec 2010 22:49

Thanks Sherington, I am able to play the youtube url by using your steps with libvlc. However, I used sleep function to wait through the events for playback completion which is good for testing but not for application. Could you give more details about how we could poll the media player state? I played around with libvlc_media_player_get_state() function but was not able to play the video. Could you give steps about how to poll the media player state?


Thanks,
Prashanth.

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: How to give youtube url

Postby sherington » 07 Dec 2010 09:31

Thanks Sherington, I am able to play the youtube url by using your steps with libvlc. However, I used sleep function to wait through the events for playback completion which is good for testing but not for application. Could you give more details about how we could poll the media player state? I played around with libvlc_media_player_get_state() function but was not able to play the video. Could you give steps about how to poll the media player state?
Rather than polling I think you need to get an event manager, libvlc_media_player_event_manager(), and register a callback, libvlc_event_attach(), for the events you're interested in.

The Java bindings abstract this completely with a simple listener. If you're using some other language wrapper I can't help you.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 39 guests