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

 

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

  1. Prasan Dutt

    9 years ago

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

Comments

Your email address will not be published. Required fields are marked *