Difference between revisions of "LibVLC Tutorial 0.9"

From VideoLAN Wiki
Jump to navigation Jump to search
m (+{{Lowercase}}, unescape markup/syntaxhighlight)
 
(33 intermediate revisions by 10 users not shown)
Line 1: Line 1:
 +
{{Lowercase}}
 +
{{Historical}}
 
== LibVLC Tutorial ==
 
== LibVLC Tutorial ==
  
=== Linging against LibVLC ===
+
'' This may work with 0.9 and 1.0 version, you just need to remove exception to get it to work on 1.1''
'' todo ''
 
  
=== Sample LibVLC Code ===
+
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.
  
 +
=== Linking against LibVLC ===
 +
 +
cc example.c -lvlc -o example
 +
 +
=== Sample LibVLC Code  ===
 +
 +
<syntaxhighlight lang="c">
 
  #include <stdio.h>
 
  #include <stdio.h>
  #include <vlc/libvlc.h>
+
#include <stdlib.h>
   
+
  #include <vlc/vlc.h>
  static void quit_on_exception( libvlc_exception_t * excp )
+
 
 +
  // Uncomment this line if you get a "sleep was not declared in this scope"
 +
// #include <unistd.h>
 +
 
 +
  static void raise(libvlc_exception_t * ex)
 
  {
 
  {
     if( libvlc_exception_raised( &excp );
+
     if (libvlc_exception_raised (ex))
 
     {
 
     {
           fprintf(stderr, "error: %s\n", libvlc_exception_get_message(excp) );
+
           fprintf (stderr, "error: %s\n", libvlc_exception_get_message(ex));
           exit(-1);
+
           exit (-1);
 
     }
 
     }
 
  }
 
  }
 
  int main(int argc, char* argv[])
 
  int main(int argc, char* argv[])
 
  {
 
  {
     char *vlc_args = {"-I", "dummy", "--module-path=/set/your/path/to/libvlc/module"};
+
     const char * const vlc_args[] = {
     libvlc_exception_t excp;
+
              "-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_exception_t ex;
 
     libvlc_instance_t * inst;
 
     libvlc_instance_t * inst;
     libvlc_media_instance_t *mi;
+
     libvlc_media_player_t *mp;
     libvlc_media_descriptor_t *md;
+
     libvlc_media_t *m;
 
      
 
      
     libvlc_exception_init( &excp );
+
     libvlc_exception_init (&ex);
 
     /* init vlc modules, should be done only once */
 
     /* init vlc modules, should be done only once */
     inst = libvlc_new( args, 3, &excp );
+
     inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &ex);
     quit_on_exception( &excp );
+
     raise (&ex);
 
    
 
    
 
     /* Create a new item */
 
     /* Create a new item */
     md = libvlc_media_descriptor_new( int, "http://mycool.movie.com/test.mov", &excp );
+
     m = libvlc_media_new (inst, "http://mycool.movie.com/test.mov", &ex);
     quit_on_exception( &excp );
+
     raise (&ex);
 
      
 
      
 
     /* XXX: demo art and meta information fetching */
 
     /* XXX: demo art and meta information fetching */
 
      
 
      
     /* Create a media instance playing environement */
+
     /* Create a media player playing environement */
     mi = libvlc_media_instance_new_from_media_descriptor( int, md, &excp );
+
     mp = libvlc_media_player_new_from_media (m, &ex);
     quit_on_exception( &excp );
+
     raise (&ex);
 
      
 
      
     /* No need to keep the media descriptor now */
+
     /* No need to keep the media now */
     libvlc_media_descriptor_release( md );
+
     libvlc_media_release (m);
 
   
 
   
 
  #if 0
 
  #if 0
     /* This is a non working code that show how to hook into a window
+
     /* This is a non working code that show how to hooks into a window,
      * if we have a window around */
+
      * if we have a window around */
 
       libvlc_drawable_t drawable = xdrawable;
 
       libvlc_drawable_t drawable = xdrawable;
 
     /* or on windows */
 
     /* or on windows */
 
       libvlc_drawable_t drawable = hwnd;
 
       libvlc_drawable_t drawable = hwnd;
 
   
 
   
       libvlc_media_instance_set_drawable( mi, drawable, &excp );
+
       libvlc_media_player_set_drawable (mp, drawable, &ex);
       quit_on_exception( &excp );
+
       raise (&ex);
 
  #endif
 
  #endif
 
   
 
   
     /* play the media_instance */
+
     /* play the media_player */
     libvlc_media_instance_play( mi, &excp );
+
     libvlc_media_player_play (mp, &ex);
     quit_on_exception( &excp );
+
     raise (&ex);
 
      
 
      
     sleep(10); /* Let it play a bit */
+
     sleep (10); /* Let it play a bit */
 
      
 
      
 
     /* Stop playing */
 
     /* Stop playing */
     libvlc_media_instance_stop( mi, &excp );
+
#warning There is known deadlock bug here. Please update to LibVLC 1.1!
 +
     libvlc_media_player_stop (mp, &ex);
 
   
 
   
     /* Free the media_instance */
+
     /* Free the media_player */
     libvlc_media_instance_release( mi, &excp );
+
     libvlc_media_player_release (mp);
 
   
 
   
     libvlc_instance_destroy( inst );
+
     libvlc_release (inst);
 +
    raise (&ex);
 
   
 
   
 
     return 0;
 
     return 0;
 
  }
 
  }
 +
</syntaxhighlight>
 +
 +
[[Category:libVLC]]

Latest revision as of 09:04, 4 March 2019

This page is obsolete and kept only for historical interest. It may document features that are obsolete, superseded, or irrelevant. Do not rely on the information here being up-to-date.

LibVLC Tutorial

This may work with 0.9 and 1.0 version, you just need to remove exception to get it to work on 1.1

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.

Linking against LibVLC

cc example.c -lvlc -o example

Sample LibVLC Code

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

 // Uncomment this line if you get a "sleep was not declared in this scope"
 // #include <unistd.h>

 static void raise(libvlc_exception_t * ex)
 {
     if (libvlc_exception_raised (ex))
     {
          fprintf (stderr, "error: %s\n", libvlc_exception_get_message(ex));
          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 */
               "--plugin-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 (&ex);
     /* init vlc modules, should be done only once */
     inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &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 (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 */
 #warning There is known deadlock bug here. Please update to LibVLC 1.1!
     libvlc_media_player_stop (mp, &ex);
 
     /* Free the media_player */
     libvlc_media_player_release (mp);
 
     libvlc_release (inst);
     raise (&ex);
 
     return 0;
 }