A simple C program to play mp3 using libvlc

后端 未结 1 1423
死守一世寂寞
死守一世寂寞 2020-12-29 17:48

I am an average C/C++ programmer. Recently I took a project to make a media player with a smart playlist that will work like Zune\'s SmartDj. I have decided to use libvlc fo

相关标签:
1条回答
  • 2020-12-29 18:07

    be sure that you have installed the following packages (else install it):

    $ apt-get install libvlccore-dev libvlc-dev
    

    test.c:

    #include <stdio.h>
    #include <stdlib.h>
    
    #include <vlc/vlc.h>
    
    int main(int argc, char **argv)
    {
        libvlc_instance_t *inst;
        libvlc_media_player_t *mp;
        libvlc_media_t *m;
    
        // load the vlc engine
        inst = libvlc_new(0, NULL);
    
        // create a new item
        m = libvlc_media_new_path(inst, "path to MP3 file");
    
        // create a media play playing environment
        mp = libvlc_media_player_new_from_media(m);
    
        // no need to keep the media now
        libvlc_media_release(m);
    
        // play the media_player
        libvlc_media_player_play(mp);
    
        sleep(10);
    
        // stop playing
        libvlc_media_player_stop(mp);
    
        // free the media_player
        libvlc_media_player_release(mp);
    
        libvlc_release(inst);
    
    
        return 0;
    }
    

    how to link and compile:

    $ gcc $(pkg-config --cflags libvlc) -c test.c -o test.o
    
    $ gcc test.o -o test $(pkg-config --libs libvlc)
    
    0 讨论(0)
提交回复
热议问题