Page 1 of 1

Problem to get duration

Posted: 10 May 2013 18:43
by milink
Hi !
(sorry for my bad english !)
I discovered libVLC yesterday and I tried it.
However I have a problem. I would get the duration of a media, but this code returns -1 two times. In the documentation, it is written that -1 means there is a problem. But I don't know where... :(

Code: Select all

#include <stdio.h> #include <stdlib.h> #include <vlc/vlc.h> #include <unistd.h> int main(int argc, char* argv[]) { libvlc_instance_t * inst; libvlc_media_player_t *mp; libvlc_media_t *m; /* Load the VLC engine */ inst = libvlc_new (0, NULL); if(inst == NULL) return 0; /* Create a new item */ m = libvlc_media_new_path(inst, "C:\\Users\\Philippe\\Desktop\\Wildlife.wmv"); if(m == NULL) return 0; libvlc_time_t duration; duration = libvlc_media_get_duration(m); printf("%d", duration); /* Create a media player playing environement */ mp = libvlc_media_player_new_from_media (m); duration = libvlc_media_player_get_length(mp); printf("\n%d", duration); /* No need to keep the media now */ libvlc_media_release (m); /* Free the media_player */ libvlc_media_player_release (mp); libvlc_release (inst); printf("\nOk"); return 0; }
Please, say me where is my error.

Re: Problem to get duration

Posted: 13 May 2013 13:56
by mangokm40
Read about events in libvlc. You might need to catch the "playing" event before calling the function that gives you duration.

Re: Problem to get duration

Posted: 13 May 2013 18:35
by milink
I did this:

Code: Select all

libvlc_media_parse(m); printf("%d", libvlc_media_get_duration(m));
And it returns correctly the duration in ms.

I didn't know there are events in libvlc. Where can I read about it ?
How did you do to get the duration with your way ?

Re: Problem to get duration

Posted: 14 May 2013 15:54
by mangokm40
I think you can read about events here:

http://www.videolan.org/developers/vlc/ ... gen/html/‎

It doesn't matter what I did. I'm a fool. You'll do it much better. :)