0

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.

glglgl
  • 89,107
  • 13
  • 149
  • 217

1 Answers1

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