Difference between revisions of "LibVLC Tutorial"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 1: Line 1:
 
== LibVLC Tutorial ==
 
== LibVLC Tutorial ==
  
'' This may work with trunk version ''
+
This code is written for LibVLC version 1.1.0 or later. It '''cannot''' be compiled with older versions.
  
Of course, windows binary builds don't come with vlc.h, so you'll need a copy of the source to get them. See [[LibVLC_Tutorial_086c]] for some instructions on getting the build working.
+
Note that VLC binary installers for Windows do not include the LibVLC SDK (it would be a waste of bandwidth and space for most users). See [[LibVLC_Tutorial_086c]] for some instructions on getting the build working.
  
 
=== Linking against LibVLC ===
 
=== Linking against LibVLC ===
  
 +
<pre>
 
cc example.c -lvlc -o example
 
cc example.c -lvlc -o example
 +
</pre>
  
 
=== Sample LibVLC Code ===
 
=== Sample LibVLC Code ===
  
 +
<pre>
 
  #include <stdio.h>
 
  #include <stdio.h>
 
  #include <stdlib.h>
 
  #include <stdlib.h>
Line 62: Line 65:
 
     return 0;
 
     return 0;
 
  }
 
  }
 +
</pre>

Revision as of 19:42, 27 May 2010

LibVLC Tutorial

This code is written for LibVLC version 1.1.0 or later. It cannot be compiled with older versions.

Note that VLC binary installers for Windows do not include the LibVLC SDK (it would be a waste of bandwidth and space for most users). See LibVLC_Tutorial_086c for some instructions on getting the build working.

Linking against LibVLC

cc example.c -lvlc -o example

Sample LibVLC Code

 #include <stdio.h>
 #include <stdlib.h>
 #include <vlc/vlc.h>
 
 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 */
               "--plugin-path=/set/your/path/to/libvlc/module/if/you/are/on/windows/or/macosx" };
     libvlc_instance_t * inst;
     libvlc_media_player_t *mp;
     libvlc_media_t *m;
     
     /* init vlc modules, should be done only once */
     inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
  
     /* Create a new item */
     m = libvlc_media_new (inst, "http://mycool.movie.com/test.mov");
        
     /* Create a media player playing environement */
     mp = libvlc_media_player_new_from_media (m);
     
     /* 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_media_player_set_xdrawable (mp, xdrawable);
     /* or on windows */
      libvlc_media_player_set_hwnd (mp, hwnd);
     /* or on mac os */
      libvlc_media_player_set_nsobject (mp, view);
  #endif
 
     /* play the media_player */
     libvlc_media_player_play (mp);
    
     sleep (10); /* Let it play a bit */
    
     /* Stop playing */
     libvlc_media_player_stop (mp);
 
     /* Free the media_player */
     libvlc_media_player_release (mp);
 
     libvlc_release (inst);
 
     return 0;
 }