LibVLC Tutorial 0.9: Difference between revisions
Jump to navigation
Jump to search
Pdherbemont (talk | contribs) →Sample LibVLC Code: --ignore-config |
Pdherbemont (talk | contribs) Simplification in names |
||
| Line 12: | Line 12: | ||
#include <vlc/libvlc.h> | #include <vlc/libvlc.h> | ||
static void | static void raise( libvlc_exception_t * excp ) | ||
{ | { | ||
if( libvlc_exception_raised( &excp ); | if( libvlc_exception_raised( &excp ); | ||
| Line 26: | Line 26: | ||
"--ignore-config", /* Don't use VLC's config */ | "--ignore-config", /* Don't use VLC's config */ | ||
"--module-path=/set/your/path/to/libvlc/module/if/you/are/on/windows/or/macosx" }; | "--module-path=/set/your/path/to/libvlc/module/if/you/are/on/windows/or/macosx" }; | ||
libvlc_exception_t | libvlc_exception_t ex; | ||
libvlc_instance_t * inst; | libvlc_instance_t * inst; | ||
libvlc_media_player_t *mp; | libvlc_media_player_t *mp; | ||
| Line 33: | Line 33: | ||
libvlc_exception_init( &excp ); | libvlc_exception_init( &excp ); | ||
/* init vlc modules, should be done only once */ | /* init vlc modules, should be done only once */ | ||
inst = libvlc_new( sizeof(args) / sizeof(args[0]), arg, & | inst = libvlc_new( sizeof(args) / sizeof(args[0]), arg, &ex ); | ||
raise( &ex ); | |||
/* Create a new item */ | /* Create a new item */ | ||
m = libvlc_media_new( inst, "http://mycool.movie.com/test.mov", & | m = libvlc_media_new( inst, "http://mycool.movie.com/test.mov", &ex ); | ||
raise( &ex ); | |||
/* XXX: demo art and meta information fetching */ | /* XXX: demo art and meta information fetching */ | ||
/* Create a media player playing environement */ | /* Create a media player playing environement */ | ||
mp = libvlc_media_player_new_from_media_descriptor( m, & | mp = libvlc_media_player_new_from_media_descriptor( m, &ex ); | ||
raise( &ex ); | |||
/* No need to keep the media now */ | /* No need to keep the media now */ | ||
| Line 56: | Line 56: | ||
libvlc_drawable_t drawable = hwnd; | libvlc_drawable_t drawable = hwnd; | ||
libvlc_media_player_set_drawable( mp, drawable, & | libvlc_media_player_set_drawable( mp, drawable, &ex ); | ||
raise( &ex ); | |||
#endif | #endif | ||
/* play the media_player */ | /* play the media_player */ | ||
libvlc_media_player_play( mp, & | libvlc_media_player_play( mp, &ex ); | ||
raise( &ex ); | |||
sleep(10); /* Let it play a bit */ | sleep(10); /* Let it play a bit */ | ||
/* Stop playing */ | /* Stop playing */ | ||
libvlc_media_player_stop( mp, & | libvlc_media_player_stop( mp, &ex ); | ||
/* Free the media_player */ | /* Free the media_player */ | ||
libvlc_media_player_release( mp, & | libvlc_media_player_release( mp, &ex ); | ||
libvlc_release( inst, & | libvlc_release( inst, &ex ); | ||
raise( &ex ); | |||
return 0; | return 0; | ||
} | } | ||
Revision as of 13:53, 10 May 2008
LibVLC Tutorial
This may work with trunk version, does not work with 0.8.6c
Linking against LibVLC
cc example.c -lvlc-control -o example
Sample LibVLC Code
#include <stdio.h>
#include <vlc/libvlc.h>
static void raise( libvlc_exception_t * excp )
{
if( libvlc_exception_raised( &excp );
{
fprintf(stderr, "error: %s\n", libvlc_exception_get_message(excp) );
exit(-1);
}
}
int main(int argc, char* argv[])
{
const char * const vlc_args[] = {
"-I", "dummy", /* Don't use any interface */
"--ignore-config", /* Don't use VLC's config */
"--module-path=/set/your/path/to/libvlc/module/if/you/are/on/windows/or/macosx" };
libvlc_exception_t ex;
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
libvlc_exception_init( &excp );
/* init vlc modules, should be done only once */
inst = libvlc_new( sizeof(args) / sizeof(args[0]), arg, &ex );
raise( &ex );
/* Create a new item */
m = libvlc_media_new( inst, "http://mycool.movie.com/test.mov", &ex );
raise( &ex );
/* XXX: demo art and meta information fetching */
/* Create a media player playing environement */
mp = libvlc_media_player_new_from_media_descriptor( m, &ex );
raise( &ex );
/* No need to keep the media now */
libvlc_media_release( m );
#if 0
/* This is a non working code that show how to hooks into a window,
* if we have a window around */
libvlc_drawable_t drawable = xdrawable;
/* or on windows */
libvlc_drawable_t drawable = hwnd;
libvlc_media_player_set_drawable( mp, drawable, &ex );
raise( &ex );
#endif
/* play the media_player */
libvlc_media_player_play( mp, &ex );
raise( &ex );
sleep(10); /* Let it play a bit */
/* Stop playing */
libvlc_media_player_stop( mp, &ex );
/* Free the media_player */
libvlc_media_player_release( mp, &ex );
libvlc_release( inst, &ex );
raise( &ex );
return 0;
}