LibVLC Tutorial 0.9

From VideoLAN Wiki
Revision as of 20:18, 15 July 2007 by Pdherbemont (talk | contribs) (Initial Creation.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

LibVLC Tutorial

Linging against LibVLC

todo

Sample LibVLC Code

#include <stdio.h>
#include <vlc/libvlc.h>
   
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_instance_new( args, 3, &excp );
    if( libvlc_exception_raised( &excp );
    {
         fprintf(stderr, "can't init libvlc\n");
         exit(-1);
    }
    
    /* Create a new item */
    md = libvlc_media_descriptor_new( int, "http://mycool.movie.com/test.mov", &excp );
    if( libvlc_exception_raised( &excp );
    {
         fprintf(stderr, "can't create a media descriptor\n");
         exit(-1);
    }
   
    /* XXX: demo art and meta information fetching */
   
    /* Create a media instance playing environement */
    mi = libvlc_media_instance_new_from_media_descriptor( int, md, &excp );
    if( libvlc_exception_raised( &excp );
    {
         fprintf(stderr, "can't create a media instance\n");
         exit(-1);
    }
   
    /* No need to keep the media descriptor now */
    libvlc_media_descriptor_release( md );

    /* libvlc_media_instance_set_drawable() --not working yet */

    libvlc_media_instance_play( mi, &excp );
    if( libvlc_exception_raised( &excp );
    {
         fprintf(stderr, "can't create play a media instance\n");
         exit(-1);
    }
   
    sleep(10); /* Let it play a bit */
   
    /* No need to keep the media descriptor now */
    libvlc_media_instance_stop( mi, &excp );

    /* No need to keep the media instance now */
    libvlc_media_instance_release( mi, &excp );

    libvlc_instance_destroy( inst );

    return 0;
}