A simple program to play mp3 using libvlc

I am an average C / C ++ programmer. I recently took a project to create a media player with a smart playlist that will work like Zune SmartDj. I decided to use libvlc for playback.

I have never coded open source software before, so I don't know anything about git and everything. Could you help me write at least C program for playing mp3 file?

Where to begin? How do you extract a song artist and other information from the mp3 file itself?

Sincerely.

+5
source share
1 answer

make sure to install the following packages (otherwise 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)
+12

All Articles