Simple Audio playing sample with LibVLC
In this blog i will demonstrate how to play mp3 file using simple LibVLC code.
- First you need to install LibVLC into your system. if you not, follow how to install tutorial to install LibVLC.
- Create new audio.c file on your home directory in ubuntu with below content.
int main(int argc, char **argv)
// load the vlc engine
inst = libvlc_new(0, NULL);
// create a new item
m = libvlc_media_new_path(inst, "/home/audio.mp3");
// create a media play playing environment
mp = libvlc_media_player_new_from_media(m);
// no need to keep the media now
// play the media_player
sleep(100);//play the audio 100s
// stop playing
// free the media_player
- you need place mp3 file named audio.mp3 in your home directory.
- then navigate to the directory where you save audio.c and simply hit this to compile the audio.c file.
gcc $(pkg-config --cflags libvlc) -c audio.c -o audio.o
gcc audio.o -o audio $(pkg-config --libs libvlc)
- Hit this on the ubuntu terminal to run your audio playing example.