Difference between revisions of "LibVLC Tutorial 0.9"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
== LibVLC Tutorial ==
 
== LibVLC Tutorial ==
  
=== Linging against LibVLC ===
+
=== Linking against LibVLC ===
'' todo ''
+
 
 +
Using libvlc 0.8.6c and cygwin gcc 3.4, you can link with libvlc like this:
 +
 
 +
1. Set your $path to include the directory which contains libvlc.dll and
 +
the plugins directory.  For example, add "c:\program files\videolan" in
 +
a relatively standard installation.
 +
 
 +
2. In your Makefile, define a variable which points to your installation:
 +
VLC_INST = "c:\program files\videolan"
 +
 
 +
3. In your Makefile, add the -L and -l option to gcc:
 +
-L$(VLC_INST) -llibvlc
  
 
=== Sample LibVLC Code ===
 
=== Sample LibVLC Code ===

Revision as of 18:25, 19 August 2007

LibVLC Tutorial

Linking against LibVLC

Using libvlc 0.8.6c and cygwin gcc 3.4, you can link with libvlc like this:

1. Set your $path to include the directory which contains libvlc.dll and the plugins directory. For example, add "c:\program files\videolan" in a relatively standard installation.

2. In your Makefile, define a variable which points to your installation: VLC_INST = "c:\program files\videolan"

3. In your Makefile, add the -L and -l option to gcc: -L$(VLC_INST) -llibvlc

Sample LibVLC Code

#include <stdio.h>
#include <vlc/libvlc.h>

static void quit_on_exception( 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[])
{
    char *vlc_args = {"-I", "dummy", "--module-path=/set/your/path/to/libvlc/module"};
    libvlc_exception_t excp;
    libvlc_instance_t * inst;
    libvlc_media_instance_t *mi;
    libvlc_media_descriptor_t *md;
    
    libvlc_exception_init( &excp );
    /* init vlc modules, should be done only once */
    inst = libvlc_new( args, 3, &excp );
    quit_on_exception( &excp );
 
    /* Create a new item */
    md = libvlc_media_descriptor_new( int, "http://mycool.movie.com/test.mov", &excp );
    quit_on_exception( &excp );
   
    /* XXX: demo art and meta information fetching */
   
    /* Create a media instance playing environement */
    mi = libvlc_media_instance_new_from_media_descriptor( int, md, &excp );
    quit_on_exception( &excp );
    
    /* No need to keep the media descriptor now */
    libvlc_media_descriptor_release( md );

#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_instance_set_drawable( mi, drawable, &excp );
     quit_on_exception( &excp );
#endif

    /* play the media_instance */
    libvlc_media_instance_play( mi, &excp );
    quit_on_exception( &excp );
   
    sleep(10); /* Let it play a bit */
   
    /* Stop playing */
    libvlc_media_instance_stop( mi, &excp );

    /* Free the media_instance */
    libvlc_media_instance_release( mi, &excp );

    libvlc_instance_destroy( inst );

    return 0;
}