• 首页
  • 文件
  • 下载
  • 状态
  • 常见问题
  • 邮件列表
  • 应用程序
  • 外部链结
  • 版权
  • 志愿者
  • 联络

示范程序:播放音讯档

「CIOS音讯核心」播放音讯档的方式极为简单,仅需一行程序。

#include "CiosAudio.hpp"

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


您必须要在编译的设定上,加上
  • CAUTILITIES
  • FFMPEGLIB

一般是在编译时加上"-DCAUTILITIES -DFFMPEGLIB"。

这两个定义。也可以直接在#include "CiosAudio.hpp"之前直接加上

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


编译时需要连结的函式库,每个平台均不相同,请见《一 般编译须知》。

平行播放

如果您希望播放音讯档是不会阻塞主程序的程序,您必须使用Thread。您可以自行写一个线绪程序,或是继承使用CIOS Audio Core当中附带的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 ;
}

CaPlay当中的示范


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++                                                                   ;
  }                                                                        ;
}                                                                          ;