Page 1 of 1

Media path is getting the application path inserted in front

Posted: 30 Sep 2013 09:51
by Marc Kupper
I'm experimenting with LibVLC 2.1.0. I want to play a video that's in "dvd:///F:" It's failing with the error being that the path to the media I want to play is getting the current directory inserted in front of it. I've created a test app that shows just the failure point.

Code: Select all

int main(int argc, char **argv) { char * szMedia; libvlc_instance_t * vlcInstance; libvlc_media_t * vlcMedia; const char * cszMrl; szMedia = "dvd:///F:"; argv++; if (*argv) szMedia = *argv; vlcInstance = libvlc_new(0, NULL); if (vlcInstance != NULL) { vlcMedia = libvlc_media_new_path (vlcInstance, szMedia); if (vlcMedia != NULL) { cszMrl = libvlc_media_get_mrl (vlcMedia); if (cszMrl != NULL) printf ("media resource locator: %s\n", cszMrl); else fprintf(stderr, "Error, libvlc_media_get_mrl() returns NULL: %s\n", libvlc_errmsg ()); libvlc_media_release (vlcMedia); } else { fprintf(stderr, "Error, libvlc_media_new_path() failed: %s\n", libvlc_errmsg ()); } libvlc_release (vlcInstance); vlcInstance = NULL; } else { fprintf(stderr, "Error, libvlc_new() failed: %s\n", libvlc_errmsg ()); } return 0; }
The output from that program is "media resource locator: file:///C:/tmp/dvd%3A%2F%2F%2FF%3A"

"file:///C:/tmp/" is the current directory. If I 'cd' somewhere else then the "file:///C:/tmp/" part changes to whatever directory I'm in. Why is the current directory getting inserted like this?

On the theory I was dealing with compiler weirdness I made the media name configurable and have that in the code above. If I run "test-vlclib test" then the output is: "media resource locator: file:///C:/tmp/test"

I have VLC 2.1.0 installed and am I'm compiling with Visual Studio 2010 Express. It's running on Windows Vista.

Marc

Re: Media path is getting the application path inserted in f

Posted: 30 Sep 2013 09:59
by sherington
Did you try libvlc_media_new_location() ?

Re: Media path is getting the application path inserted in f

Posted: 30 Sep 2013 18:50
by Marc Kupper
Did you try libvlc_media_new_location() ?
Not yet - I got the test application I posted above to work by downgrading VLC from 2.1.0 to 2.0.8. I also ran the the same test application on a Windows 7 machine and had the same results. With VLC 2.0.7 the MRL returned is "dvd:///F:." I updated VLC on the win7 to 2.1.0 and the MRL is reported as "file:///Z:/test-LibVLC/dvd%3A%2F%2F%2FF%3A"

I don't know if it's a bug with VLC 2.1.0 or an intended behavioral change. I'll test with libvlc_media_new_location().

Marc

Re: Media path is getting the application path inserted in f

Posted: 30 Sep 2013 19:27
by Marc Kupper
libvlc_media_new_location() works fine and the MRL gets set to "dvd:///F:" Thank you.

It appears I got caught by a "gotcha" behavioral change with libvlc_media_new_path() where starting with VLC 2.1.0 it forces prefixing the string you pass to it with the current directory. It used to be that media_new_path() inspected the string and if it was an absolute path it would use it otherwise it would prefix.

At present if you do a "check for updates" from VLC 2.0.8 or older it brings people up to VLC 2.0.8 meaning not many people are on VLC 2.1.0 yet. It'll be interesting to see if people have been using libvlc_media_new_path() with an absolute path. For example, the LibVLC_Tutorial article offers a sample application that uses

Code: Select all

libvlc_media_new_path (inst, "http://mycool.movie.com/test.mov");
Installing VLC 2.1.0 breaks that sample code and the resulting MRL is "file:///C:/current-directory/http%3A%2F%2Fmycool.movie.com%2Ftest.mov"

Marc

Re: Media path is getting the application path inserted in f

Posted: 30 Sep 2013 21:53
by RĂ©mi Denis-Courmont
I think the official Doxygen documentation is clear about the fact that ..._location() takes a URL and ..._path() a file path - and the current wording is three years old.

Certainly a lot of LibVLC samples are badly written. Many of them convey useless cargo cult, and the worst ones are just plain wrong. You should not copy sample code from random places, and this is not just about LibVLC.