I have tried using the fmod.h include file in C. But the tutorial I found for it was old/obsolete. Please can anyone give a program or an explanation as to how am I supposed to play some file in a C program using its libraries? Thanks in advance. Detailed explanation would be appreciated.
Asked
Active
Viewed 4,107 times
0
-
1Also on which platform you are working? – Jayesh Bhoi Sep 02 '14 at 05:33
-
2Standard C99 does not know about music or sound. You need to use system specific libraries at least. – Basile Starynkevitch Sep 02 '14 at 05:35
-
1In linux you can try `libvlc`. [check here](http://stackoverflow.com/questions/10116783/a-simple-c-program-to-play-mp3-using-libvlc) and for `FMOD` using see http://stackoverflow.com/questions/428884/how-to-play-mp3-files-in-c?lq=1 – Jayesh Bhoi Sep 02 '14 at 05:37
-
@Jayesh I am working on Ubuntu 14.04 LTS 64 bit. – Rutuparna Damle Sep 02 '14 at 06:23
-
@RutuparnaDamle ok then see my previous comment. – Jayesh Bhoi Sep 02 '14 at 06:24
-
@BasileStarynkevitch What do you mean by System specific libraries? Can you elaborate? – Rutuparna Damle Sep 02 '14 at 06:24
-
You could use [ALSA](http://en.wikipedia.org/wiki/Advanced_Linux_Sound_Architecture) APIs. ALSA gives you good control over Audio configuration, and is part of Linux Kernel. [Here](http://equalarea.com/paul/alsa-audio.html) are good tutorial to start with. – Saurabh Meshram Sep 02 '14 at 06:30
1 Answers
3
As you are working on Ubuntu, libvlc
would be handy to use.
You should find the necessary files (libvlc.so, libvlc.pc, header files...) in a binary package called libvlc-dev.
Install it like :
sudo apt-get install libvlccore-dev libvlc-dev
Then here is the test program to play a file :
#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 engine
inst = libvlc_new(0, NULL);
// create a file to play
m = libvlc_media_new_path(inst, "myFile.mp3");
// create a media play playing environment
mp = libvlc_media_player_new_from_media(m);
// release the media now.
libvlc_media_release(m);
// play the media_player
libvlc_media_player_play(mp);
sleep(10); // let it play for 10 seconds
// stop playing
libvlc_media_player_stop(mp);
// free the memory.
libvlc_media_player_release(mp);
libvlc_release(inst);
return 0;
}

Sagar D
- 2,588
- 1
- 18
- 31