Using Omxplayer And System
This will play an audio file but it won’t return until playing is complete.
#include <stdlib.h>
system("omxplayer /home/pi/projects/my_project/audio/my_audio.wav");
Play On A Background Thread
This will trigger omxplayer on a separate thread and return immediately so your program execution doesn’t stall until the file has finished playing. You can even use this multiple times and have multiple instances of omxplayer playing on top of each other.
int pid;
pid=fork();
if(pid==0)
{
//printf("I am the child\n");
execlp("/usr/bin/omxplayer", " ", "/home/pi/projects/my_project/audio/my_file.wav", NULL); //Execute file: file, arguments (1 or more strings followed by NULL)
_exit(0);
}
else
{
//printf("I am the parent\n");
wait();
}
Closing Player On Background Thread
system("killall omxplayer.bin");
Adjusting Playback Of Omxplayer On A Background Thread
Resources:
http://www.raspberrypi.org/forums/viewtopic.php?f=38&t=7987

11 years ago
Really helped the closing player command. I can play multiple audio files using this command.