• Home
  • Documents
  • Download
  • Status
  • FAQ
  • Mailing list
  • Applications
  • Links
  • License
  • Volunteers
  • Contacts

Examples : Play audio files with FFmpeg

Play an audio file with CIOS Audio Core is extremely easy, you need only one line of code, not even codes.

#include "CiosAudio.hpp"

int main(int argc,char * argv[])
{
  if (argc<2) return 0 ;
  CiosAudio::MediaPlay(argv[1]) ;
  return 1 ;
}


You wiil have to add DEFINEs to your C++ compiler settings:
  • CAUTILITIES
  • FFMPEGLIB

Normally, it is a CXXFLAGS with "-DCAUTILITIES -DFFMPEGLIB".

You can define these two DEFINEs directly before #include "CiosAudio.hpp".

#define CAUTILITIES 1
#define FFMPEGLIB 1
#include "CiosAudio.hpp"


Not every platforms link with the same libraries. Please read <Common knowledge of compilation>.

Parallel Playing an audio file

If you wish the playing action will not block your main program, you will have to use Thread. You can write your own thread program, or inherit from CIOS Audio Core class "Thread".

#include "CiosAudio.hpp"

namespace CiosAudio {

class MyThread : Thread
{
  public:

    int started ;

    explicit MyThread(void) ;
    virtual ~MyThread(void) ;

  protected:

    virtual void run (int Type,ThreadData * Data) ;

};

MyThread::MyThread(void)
  :Thread()
{
  started = 0 ;
}

MyThread::~MyThread(void)
{
}

void MyThread::run(int Type,ThreadData * Data)
{
  if ( 1001 != Type ) return ;
  started = 1 ;
  MediaPlay(Data->Arguments) ;
  started = 0 ;
}

}

int main(int argc,char * argv[])
{
  if (argc<2) return 0 ;
  CiosAudio::MyThread myThread ;
  myThread.start(1001,argv[1]);
  do {
    Timer::Sleep(1000) ;
  } while ( 1 == myThread.started ) ;
  return 1 ;
}

Example in CaPlay.cpp


int                   at       = -1                                        ;
int deviceId = -1 ; int decodeId = -1 ;
bool                  debug    = false                                     ;
CiosAudio::Debugger * debugger = NULL                                      ;
while ( at < argc )                                                        {
  if ( 0 == strcmp(argv[at],"--output") )                                  {
    at++                                                                   ;
    deviceId = atoi(argv[at])                                              ;
    at++                                                                   ;
  } else
  if ( 0 == strcmp(argv[at],"--decode") )                                  {
    at++                                                                   ;
    decodeId = atoi(argv[at])                                              ;
    at++                                                                   ;
  } else
  if ( 0 == strcmp(argv[at],"--debug" ) )                                  {
    at++                                                                   ;
    debug = true                                                           ;
  } else                                                                   {
    if ( debug && ( NULL == debugger ) )                                   {
      debugger = new CiosAudio::Debugger ( )                               ;
    }                                                                      ;
    CiosAudio::MediaPlay ( argv [ at ] , deviceId , decodeId , debugger )  ;
    at++                                                                   ;
  }                                                                        ;
}                                                                          ;