Problem to get duration

This forum is about all development around libVLC.
milink
New Cone
New Cone
Posts: 6
Joined: 10 May 2013 18:33

Problem to get duration

Postby milink » 10 May 2013 18:43

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.

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: Problem to get duration

Postby mangokm40 » 13 May 2013 13:56

Read about events in libvlc. You might need to catch the "playing" event before calling the function that gives you duration.

milink
New Cone
New Cone
Posts: 6
Joined: 10 May 2013 18:33

Re: Problem to get duration

Postby milink » 13 May 2013 18:35

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 ?

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: Problem to get duration

Postby mangokm40 » 14 May 2013 15:54

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. :)


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 22 guests