使用音频引擎MITA处理播放器列表的源代码


#include "../../include/mita.h" /**< @brief MITA SDK Header */
#ifdef _DEBUG
#pragma comment(lib, "../../library/mitaD.lib")
#else
#pragma comment(lib, "../../library/mita.lib")
#endif

#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>

#pragma warning(push)
#pragma warning(disable:4996)

MITA_STATIC
MITA_INLINE
MITA_VOID
MITA_CheckError(MITA_VOID)
{
MITA_ERROR lastError = MITA_GetLastError();
if (lastError != MITA_ERROR_OK)
{
printf("ERROR: MITA Framework error with %u codes\n", lastError);
exit(lastError);
}
}

MITA_STATIC
MITA_INLINE
MITA_BYTE
MITA_EnterKey(MITA_VOID)
{
MITA_INT32 key = 0xFF;
do
{
if (kbhit())
{
key = getch();
break;
}
Sleep(10);
} while (1);
if (key >= 'a' && key <= 'z')
key -= 32;
return key;
}

//
//ChannelMask must has channel number in high 8 bits.
// | 00000000 | MMMMMMMM MMMMMMMM MMMMMMMM |
// Nums ChannelMask
//How to set number?
// MITA_CHNFMT_SetNum(Mask, 2)
//Also you can use MITA_GuessChannelMode.
//
// The channel number must equal with channel mask.
// ChannelMask = MITA_CP_FRONT_LEFT|MITA_CP_FRONT_RIGHT; //Use two speaker
// MITA_CHNFMT_SetNum(ChannelMask, 2); //Set 2
//
MITA_STATIC
MITA_INLINE
MITA_HOUTPUT
MITA_CreateDefaultOutput(MITA_HINSTANCE hInstance, MITA_DWORD ChannelMask)
{
MITA_HOUTPUT hOutput;
MITA_HDEVICE hDevice;
MITA_DEVICEPARAM Param;
MITA_SIZE i, n;
MITA_DEVICEINFO DevInfo;
MITA_BYTE Key = 'A';
MITA_DWORD Ids[10];
MITA_BYTE MaxIds = 0;

MITA_Ins_CreateObject(hInstance, &IID_DevWinMME, &hDevice);
MITA_CheckError();

MITA_Device_GetDeviceNums(hDevice, &n);
MITA_CheckError();

printf("\nSelect a output device: \n");
_try_again:
Key = 'A';
for (i = 0; i < n; i++)
{
MITA_Device_GetDevice(hDevice, i, &DevInfo);
MITA_CheckError();
if (DevInfo.Type == MITA_CT_OUTPUT)
{
Ids[Key - 'A'] = DevInfo.DevId;
printf("[%c] Device %s [%f - %f]\n", Key, MITA_Text_ToSystemS(DevInfo.DevName, MITA_TCT_DEFAULT), DevInfo.Latency[0], DevInfo.Latency[1]);
Key++;
MaxIds++;
}
}
Key = MITA_EnterKey() - 'A';
if (Key >= MaxIds)
{
printf("ERROR: Invalid input keys, please try again.\n");
goto _try_again;
}

Param.Callback = MITA_NULL;
Param.CallbackHandle = MITA_NULL;
Param.Customer = MITA_NULL; /**< @brief for future use */
Param.ChannelFmt.mask = ChannelMask; /**< @brief The mask of channels. */
Param.ChannelFmt.sfmt = MITA_SDT_F32; /**< @brief Float32 Sample */
Param.ChannelFmt.sps = 44100.0f; /**< @brief 44.1KHz */
Param.Latency = 0.1f; /**< @brief 100 ms latency */
Param.Type = MITA_CT_OUTPUT; /**< @brief For output. */
Param.DevId = Ids[Key]; /**< @brief The id of device */

MITA_Output_CreateByDevice(hInstance, hDevice, &Param, MITA_FALSE, &hOutput);
MITA_CheckError();

return hOutput;
}

MITA_STATIC
MITA_INLINE
MITA_VOID
MITA_PrintDecSupportExts(MITA_HINSTANCE hInstance)
{
MITA_HFACTORY DecFactory;
MITA_HOBJECTLIST DecList;
MITA_SIZE i, n, j, jn;
MITA_AFD afd;
MITA_HDECODER hDecoder;
MITA_Ins_GetFactory(hInstance, MITA_MT_DECODER, &DecFactory);
MITA_CheckError();
MITA_ObjectList_Build(hInstance, DecFactory, MITA_FALSE, &DecList);
MITA_CheckError();
MITA_ObjectList_Count(DecList, &n);
for (i = 0; i < n; i++)
{
MITA_ObjectList_Get(DecList, i, &hDecoder);
MITA_Decoder_GetFileDescribeNums(hDecoder, &jn);
for (j = 0; j < jn; j++)
{
MITA_Decoder_GetFileDescribe(hDecoder, j, &afd);
printf("%s;", MITA_Text_ToSystemS(afd.ext, MITA_TCT_DEFAULT));
}
}
printf("\n");
MITA_CloseHandle(DecList);
}

MITA_STATIC
MITA_INLINE
MITA_BOOL
MITA_CALLBACK
MITA_MAPL_PutInfoHeader(MITA_APLCODEC codec, MITA_HSTREAM hStream, MITA_LPAPLINFOHEADER pInfoHdr, MITA_HANDLE hHandle)
{
MITA_SIZE WriteSize;
MITA_Stream_Write(hStream, pInfoHdr, pInfoHdr->cbSize, &WriteSize);
return MITA_TRUE;
}

MITA_STATIC
MITA_INLINE
MITA_BOOL
MITA_CALLBACK
MITA_MAPL_GetInfoHeader(MITA_APLCODEC codec, MITA_HSTREAM hStream, MITA_LPAPLINFOHEADER* pInfoHdr, MITA_HANDLE hHandle)
{
MITA_SIZE cbSize;
MITA_SIZE readSize;
MITA_Stream_Read(hStream, &cbSize, sizeof(MITA_SIZE), &readSize);
MITA_Stream_Seek(hStream, -4, 0, SEEK_CUR);
*pInfoHdr = MITA_Malloc(cbSize);
if (*pInfoHdr == MITA_NULL)
return MITA_FALSE;
MITA_Stream_Read(hStream, *pInfoHdr, cbSize, &readSize);
return MITA_TRUE;
}

MITA_STATIC
MITA_INLINE
MITA_VOID
MITA_CALLBACK
MITA_MAPL_DelInfoHeader(MITA_APLCODEC codec, MITA_LPAPLINFOHEADER pInfoHdr, MITA_HANDLE hHandle)
{
MITA_Free(pInfoHdr);
}

MITA_STATIC
MITA_INLINE
MITA_BOOL
MITA_CALLBACK
MITA_MAPL_PutItem(MITA_APLCODEC codec, MITA_HSTREAM hStream, MITA_HSOUND hItem, MITA_HANDLE hHandle)
{
MITA_WORD nExtendSize;
MITA_SIZE WriteSize;
MITA_LPBYTE pExtend;
MITA_ISound* pSound = (MITA_ISound*)hItem;
MITA_SIZE cbSize = pSound->cbSize - 12;
//
//
MITA_Stream_Write(hStream, &cbSize, sizeof(MITA_WORD), &WriteSize);
MITA_Stream_Write(hStream, &pSound->channelInfo, sizeof(MITA_CHANNELFORMAT), &WriteSize);
MITA_Stream_Write(hStream, &pSound->fBitRate, sizeof(MITA_FLOAT), &WriteSize);
MITA_Stream_Write(hStream, &pSound->fAverBitRate, sizeof(MITA_FLOAT), &WriteSize);
MITA_Stream_Write(hStream, &pSound->fQuality, sizeof(MITA_FLOAT), &WriteSize);
MITA_Stream_Write(hStream, &pSound->sTotalTime, sizeof(MITA_TIME), &WriteSize);
MITA_Stream_Write(hStream, pSound->fileType, sizeof(pSound->fileType), &WriteSize);
MITA_Stream_Write(hStream, &pSound->coderGUID, sizeof(MITA_UUID), &WriteSize);
MITA_Stream_Write(hStream, pSound->encoding, sizeof(pSound->encoding), &WriteSize);
MITA_Stream_Write(hStream, &pSound->timeRange, sizeof(MITA_TIMEPOS), &WriteSize);
MITA_Stream_Write(hStream, pSound->szPath, sizeof(pSound->szPath), &WriteSize);
MITA_Stream_Write(hStream, &pSound->nTagIndex, sizeof(MITA_BYTE), &WriteSize);
MITA_Stream_Write(hStream, &pSound->nTagNums, sizeof(MITA_BYTE), &WriteSize);
MITA_Stream_Write(hStream, pSound->szTitle, sizeof(pSound->szTitle), &WriteSize);
MITA_Stream_Write(hStream, pSound->szArtist, sizeof(pSound->szArtist), &WriteSize);
MITA_Stream_Write(hStream, pSound->szAlbum, sizeof(pSound->szAlbum), &WriteSize);
MITA_Stream_Write(hStream, pSound->szComment, sizeof(pSound->szComment), &WriteSize);
MITA_Stream_Write(hStream, pSound->szGenre, sizeof(pSound->szGenre), &WriteSize);
MITA_Stream_Write(hStream, &pSound->nTrack, sizeof(MITA_INT32), &WriteSize);
MITA_Stream_Write(hStream, &pSound->nYear, sizeof(MITA_INT32), &WriteSize);
MITA_Sound_GetExtend(hItem, &nExtendSize, &pExtend);
if (nExtendSize)
MITA_Stream_Write(hStream, pExtend, nExtendSize, &WriteSize);

//TODO: 添加你额外的写入数据代码

return MITA_TRUE;
}

MITA_STATIC
MITA_INLINE
MITA_BOOL
MITA_CALLBACK
MITA_MAPL_GetItem(MITA_APLCODEC codec, MITA_HSTREAM hStream, MITA_HSOUND* hItem, MITA_HANDLE hHandle)
{
//
//
MITA_WORD nExtendSize;
MITA_SIZE readSize;
MITA_LPBYTE pExtend;
MITA_WORD nSize;
MITA_ISound* pSound;
//
//
MITA_Stream_Read(hStream, &nSize, sizeof(MITA_WORD), &readSize);
if (!MITA_Sound_Create((MITA_HINSTANCE)(hHandle), nSize - sizeof(MITA_ISound) + 12, hItem))
return MITA_FALSE;
pSound = (MITA_ISound*)(*hItem);
MITA_Stream_Read(hStream, &pSound->channelInfo, sizeof(MITA_CHANNELFORMAT), &readSize);
MITA_Stream_Read(hStream, &pSound->fBitRate, sizeof(MITA_FLOAT), &readSize);
MITA_Stream_Read(hStream, &pSound->fAverBitRate, sizeof(MITA_FLOAT), &readSize);
MITA_Stream_Read(hStream, &pSound->fQuality, sizeof(MITA_FLOAT), &readSize);
MITA_Stream_Read(hStream, &pSound->sTotalTime, sizeof(MITA_TIME), &readSize);
MITA_Stream_Read(hStream, pSound->fileType, sizeof(pSound->fileType), &readSize);
MITA_Stream_Read(hStream, &pSound->coderGUID, sizeof(MITA_UUID), &readSize);
MITA_Stream_Read(hStream, pSound->encoding, sizeof(pSound->encoding), &readSize);
MITA_Stream_Read(hStream, &pSound->timeRange, sizeof(MITA_TIMEPOS), &readSize);
MITA_Stream_Read(hStream, pSound->szPath, sizeof(pSound->szPath), &readSize);
MITA_Stream_Read(hStream, &pSound->nTagIndex, sizeof(MITA_BYTE), &readSize);
MITA_Stream_Read(hStream, &pSound->nTagNums, sizeof(MITA_BYTE), &readSize);
MITA_Stream_Read(hStream, pSound->szTitle, sizeof(pSound->szTitle), &readSize);
MITA_Stream_Read(hStream, pSound->szArtist, sizeof(pSound->szArtist), &readSize);
MITA_Stream_Read(hStream, pSound->szAlbum, sizeof(pSound->szAlbum), &readSize);
MITA_Stream_Read(hStream, pSound->szComment, sizeof(pSound->szComment), &readSize);
MITA_Stream_Read(hStream, pSound->szGenre, sizeof(pSound->szGenre), &readSize);
MITA_Stream_Read(hStream, &pSound->nTrack, sizeof(MITA_INT32), &readSize);
MITA_Stream_Read(hStream, &pSound->nYear, sizeof(MITA_INT32), &readSize);
MITA_Sound_GetExtend(*hItem, &nExtendSize, &pExtend);
if (nExtendSize)
MITA_Stream_Read(hStream, pExtend, nExtendSize, &readSize);

//TODO: 添加你额外的读取数据代码

return MITA_TRUE;
}

MITA_STATIC
MITA_INLINE
MITA_VOID
MITA_CALLBACK
MITA_MAPL_DelItem(MITA_APLCODEC codec, MITA_HSOUND hItem, MITA_HANDLE hHandle)
{
MITA_CloseHandle(hItem);
}

typedef struct MITA_TAG_LOOPPROCHANDLE
{
MITA_HINSTANCE hInstance;
MITA_HARRAY hItemArray;
MITA_HOBJECTLIST hDecoderChain;
}MITA_LOOPPROCHANDLE;

MITA_STATIC
MITA_BOOL
MITA_CALLBACK
MITA_LoopProc(MITA_HANDLE h, MITA_LPCWSTR lpPath)
{
MITA_LOOPPROCHANDLE* Handle = (MITA_LOOPPROCHANDLE*)h;
MITA_PARAMPARSESONG Param;

Param.dwTagFlag = MITA_TAGREAD_OTHER_ID3V2_APE_ID3V1;
Param.hDecoderChain = Handle->hDecoderChain;
Param.hInstance = Handle->hInstance;
Param.hItemArray = Handle->hItemArray;
Param.hStream = MITA_NULL;
Param.nStreamBeginPos = 0;
Param.lpPath = lpPath;

MITA_Ins_Action_ParseSong(&Param);

return MITA_TRUE;
}

MITA_STATIC
MITA_INLINE
MITA_HARRAY
MITA_PraseDirectory(MITA_HINSTANCE hInstance, MITA_LPCWSTR lpDir, MITA_BOOL bIncChildDir)
{
MITA_LOOPPROCHANDLE Handle;
MITA_HFACTORY hDecoderFactory;

MITA_Ins_GetFactory(hInstance, MITA_MT_DECODER, &hDecoderFactory);
MITA_ObjectList_Build(hInstance, hDecoderFactory, MITA_FALSE, &Handle.hDecoderChain);
Handle.hInstance = hInstance;
Handle.hItemArray = MITA_Array_Create(hInstance, 1, sizeof(MITA_HSOUND), MITA_FALSE);

MITA_LoopFile(hInstance, lpDir, bIncChildDir, &Handle, MITA_LoopProc, MITA_NULL);
MITA_CloseHandle(Handle.hDecoderChain);

return Handle.hItemArray;
}

MITA_STATIC
MITA_INLINE
MITA_VOID
MITA_PrintSoundArray(MITA_HARRAY hItemArray)
{
MITA_SIZE i, n;
MITA_HSOUND hSoundItem;
MITA_WCHAR szPath[MITA_MAXPATH];
MITA_UUID coderGuid;

printf("\n");
n = MITA_Array_GetCount(hItemArray);
for (i = 0; i < n; i++)
{
MITA_Array_Get(hItemArray, i, &hSoundItem);
MITA_Sound_GetPath(hSoundItem, szPath, MITA_MAXPATH);
MITA_Sound_GetCoderGUID(hSoundItem, &coderGuid);
printf("Path: %s\n", MITA_Text_ToSystemS(szPath, MITA_TCT_DEFAULT));
}
}

MITA_STATIC
MITA_INLINE
MITA_VOID
MITA_DeleteSoundArray(MITA_HARRAY hItemArray)
{
MITA_SIZE i, n;
MITA_HSOUND hSoundItem;

n = MITA_Array_GetCount(hItemArray);
for (i = 0; i < n; i++)
{
MITA_Array_Get(hItemArray, i, &hSoundItem);
MITA_CloseHandle(hSoundItem);
}
MITA_CloseHandle(hItemArray);
}

MITA_STATIC
MITA_INLINE
MITA_VOID
MITA_SaveMAPL(MITA_HINSTANCE hInstance, MITA_LPCWSTR lpPath, MITA_HARRAY hItemArray)
{
MITA_APL_ENCPARAM_IO io;
MITA_HENCODER hMAPLEncoder;
MITA_FILEPARAM FileParam;
MITA_APLINFOHEADER* InfoHeader;

memset(&io, 0, sizeof(io));
io.io.CB_DelInfoHeader = MITA_MAPL_DelInfoHeader;
io.io.CB_DelItem = MITA_MAPL_DelItem;
io.io.CB_GetInfoHeader = MITA_NULL;
io.io.CB_PutInfoHeader = MITA_MAPL_PutInfoHeader;
io.io.CB_GetItem = MITA_NULL;
io.io.CB_PutItem = MITA_MAPL_PutItem;
io.io.CB_Handle = hInstance;
InfoHeader = (MITA_APLINFOHEADER*)MITA_Calloc(1, sizeof(MITA_APLINFOHEADER));
InfoHeader->cbSize = sizeof(MITA_APLINFOHEADER);
InfoHeader->version = 0;
InfoHeader->item_pos = sizeof(MITA_APLHEADER) + sizeof(MITA_APLINFOHEADER);
InfoHeader->text_type = MITA_TCT_UTF16LE;
io.pInfoHdr = InfoHeader;

if (!MITA_Ins_CreateObject(hInstance, &IID_EncMAPL, &hMAPLEncoder))
{
printf("ERROR: Not install cdc_mapl.dll plugin.\n");
MITA_CheckError();
return;
}
MITA_Encoder_SetParam(hMAPLEncoder, MAPL_ENCPARAM_IO, &io);

///
//你也可以选择Stream对象进行存储
FileParam.nFlag = MITA_FPF_USEPATH;
FileParam.hStream = MITA_NULL;
FileParam.lpwszPath = lpPath;

MITA_Encoder_Startup(hMAPLEncoder, &FileParam, hItemArray);
MITA_Encoder_Terminate(hMAPLEncoder);
MITA_CloseHandle(hMAPLEncoder);
}

MITA_STATIC
MITA_INLINE
MITA_HARRAY
MITA_LoadMAPL(MITA_HINSTANCE hInstance, MITA_LPCWSTR lpPath)
{
MITA_APL_DECPARAM_IO io;
MITA_HDECODER hMAPLDecoder;
MITA_FILEPARAM FileParam;
MITA_HARRAY hItemArray = MITA_NULL;

memset(&io, 0, sizeof(io));
io.io.CB_DelInfoHeader = MITA_MAPL_DelInfoHeader;
io.io.CB_DelItem = MITA_MAPL_DelItem;
io.io.CB_GetInfoHeader = MITA_MAPL_GetInfoHeader;
io.io.CB_PutInfoHeader = MITA_NULL;
io.io.CB_GetItem = MITA_MAPL_GetItem;
io.io.CB_PutItem = MITA_NULL;
io.io.CB_Handle = hInstance;

if (!MITA_Ins_CreateObject(hInstance, &IID_DecMAPL, &hMAPLDecoder))
{
printf("ERROR: Not install cdc_mapl.dll plugin.\n");
MITA_CheckError();
return MITA_NULL;
}
MITA_Decoder_SetParam(hMAPLDecoder, MAPL_ENCPARAM_IO, &io);

///
//你也可以选择Stream对象进行存储
FileParam.nFlag = MITA_FPF_USEPATH;
FileParam.hStream = MITA_NULL;
FileParam.lpwszPath = lpPath;

hItemArray = MITA_Array_Create(hInstance, 0, sizeof(MITA_HSOUND), MITA_FALSE);

MITA_Decoder_DecodeInfo(hMAPLDecoder, &FileParam, MITA_DIF_GETINFO, hItemArray);
MITA_CloseHandle(hMAPLDecoder);

return hItemArray;
}

void main(void)
{
MITA_HINSTANCE gInstance = MITA_NULL;
MITA_CHAR szVersion[64];
MITA_SIZE PluginCount = 0;
MITA_HINPUT hCurItem = MITA_NULL;
MITA_HOUTPUT hOutput;
MITA_HENGINE hEngine;
MITA_DWORD ChannelMask;
MITA_BYTE Key = 0;
MITA_TIME CurTime;
MITA_TIME DurTime;
MITA_DWORD cur_ms, dur_ms;
MITA_CHANNELFORMAT ChannelFmt;
MITA_STATUS Status;
MITA_HARRAY hItemArray = MITA_NULL;
MITA_SIZE CurItemIndex = 0;
MITA_SIZE TotalItem = 0;

printf(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n");
printf(";;Copyright(C) 杭州蜜柑科技有限公司 2008 - 2011. 保留所有权利。;;\n");
printf(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n");
printf(";;Use MAPL Example ;;\n");
printf(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n");

//
//1. Create a global instance handle.
gInstance = MITA_Initialize(MITA_NULL);
MITA_CheckError();

//
//2. Check SDK version, this was not necessary.
MITA_GetVersionStringA(szVersion, 64);
MITA_CheckError();
printf(";;MITA: Version %s\n", szVersion);

//
//3. Load all existed plugins.
MITA_Ins_LoadPluginFromDir(gInstance, L"../../plugins", &PluginCount);
MITA_CheckError();
printf(";;MITA: Load %u plugins\n", PluginCount);
printf(";;Support: ;;\n");
MITA_PrintDecSupportExts(gInstance);
printf(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n");

//
//4. Create Engine Object
MITA_Engine_Create(gInstance, MITA_ENGINEFLAG_CHECKPREPARE|MITA_ENGINEFLAG_CHECKRENDER, &hEngine);
MITA_CheckError();

//
//5. Create Output Source
MITA_GuessChannelMode(8, &ChannelMask);
hOutput = MITA_CreateDefaultOutput(gInstance, ChannelMask);

//
//6. Add source to engine.
MITA_Engine_AddSource(hEngine, hOutput);
MITA_CheckError();
MITA_Output_Startup(hOutput);
MITA_CheckError();

//
//7. Load input source
{
_try_again:
printf("\nPress S to save MAPL.\n");
printf("Press L to load MAPL.\n");
printf("Press C to continue.\n");
printf("Press Esc to exit \n");
Key = MITA_EnterKey();
switch (Key)
{
case 'c':
case 'C':
break;
case 'l':
case 'L':
{
if (hItemArray)
{
MITA_DeleteSoundArray(hItemArray);
hItemArray = MITA_NULL;
}
hItemArray = MITA_LoadMAPL(gInstance, L"../Media/test.mapl");
if (hItemArray)
MITA_PrintSoundArray(hItemArray);
}break;
case 's':
case 'S':
{
if (hItemArray)
{
MITA_DeleteSoundArray(hItemArray);
hItemArray = MITA_NULL;
}

//MAPL not has MITA_DF_DIRECTPARSE flag.
// So the parser will auto skip check mapl format file.
//If you want to use MAPL, then please write your own
// MAPL codec callbacks.
hItemArray = MITA_PraseDirectory(gInstance, L"..\\Media", MITA_TRUE);
if (hItemArray)
{
MITA_PrintSoundArray(hItemArray);
MITA_SaveMAPL(gInstance, L"../Media/test.mapl", hItemArray);
}
}break;
case 27:
goto _end;
break;
}
if (!hItemArray)
{
printf("ERROR: Not load item set, please try again.\n");
goto _try_again;
}
}
TotalItem = MITA_Array_GetCount(hItemArray);
{
MITA_HSOUND hSound;

/
//阻止MITA_Engine_DeleteSource自动移除hSound对象
for (CurItemIndex = 0; CurItemIndex < TotalItem; CurItemIndex++)
{
MITA_Array_Get(hItemArray, CurItemIndex, &hSound);
MITA_Sound_ReadOnly(hSound, MITA_TRUE);
}
CurItemIndex = 0;

MITA_Array_Get(hItemArray, CurItemIndex, &hSound);
MITA_Input_LoadBySound(gInstance, hSound, &hCurItem);
MITA_Engine_AddSource(hEngine, hCurItem);
MITA_Input_Play(hCurItem, MITA_NULL);
}

printf("\n");
printf("Press O to prev sound.\n");
printf("Press P to next sound.\n");
printf("Press Esc to exit\n");
do
{
if (kbhit())
{
Key = getch();

switch (Key)
{
case 'o':
case 'O':
{
//
//To Prev
MITA_HSOUND hSound;
MITA_Engine_DeleteSource(hEngine, hCurItem); //Delete Current Source
CurItemIndex = (CurItemIndex-1+TotalItem)%TotalItem; //Move to prev source
MITA_Array_Get(hItemArray, CurItemIndex, &hSound);
MITA_Input_LoadBySound(gInstance, hSound, &hCurItem); //load new source
MITA_Engine_AddSource(hEngine, hCurItem);
MITA_Input_Play(hCurItem, MITA_NULL);
}break;
case 'p':
case 'P':
{
//
//To Next
MITA_HSOUND hSound;
MITA_Engine_DeleteSource(hEngine, hCurItem); //Delete Current Source
CurItemIndex = (CurItemIndex+1)%TotalItem; //Move to next source
MITA_Array_Get(hItemArray, CurItemIndex, &hSound);
MITA_Input_LoadBySound(gInstance, hSound, &hCurItem); //load new source
MITA_Engine_AddSource(hEngine, hCurItem);
MITA_Input_Play(hCurItem, MITA_NULL);
}break;
}
}

MITA_Source_GetStatus(hCurItem, &Status);
MITA_Source_GetCurTime(hCurItem, &CurTime);
MITA_Input_GetDuration(hCurItem, &DurTime);
MITA_Input_GetChannelFormat(hCurItem, &ChannelFmt);
MITA_Time_Cvt(&ChannelFmt, &CurTime, MITA_TIMEUNIT_MICRSECOND, &CurTime);
MITA_Time_Cvt(&ChannelFmt, &DurTime, MITA_TIMEUNIT_MICRSECOND, &DurTime);
cur_ms = (MITA_DWORD)MITA_Time_GetData(CurTime);
dur_ms = (MITA_DWORD)MITA_Time_GetData(DurTime);

printf("%10s %02u:%02u:%02u/%02u:%02u:%02u [%u channels][%u/%u]\r", Status==MITA_STATUS_RUNNING?"playing":(Status==MITA_STATUS_PAUSE?"pause":"stop"),
cur_ms / 1000 / 60,
cur_ms / 1000 % 60,
cur_ms / 10 % 100,
dur_ms / 1000 / 60,
dur_ms / 1000 % 60,
dur_ms / 10 % 100,
MITA_CHNFMT_GetNum(ChannelFmt.mask), CurItemIndex+1, TotalItem);
if (Status == MITA_STATUS_IDLE)
{
//
//To Next
MITA_HSOUND hSound;
MITA_Engine_DeleteSource(hEngine, hCurItem); //Delete Current Source
CurItemIndex = (CurItemIndex+1)%TotalItem; //Move to next source
MITA_Array_Get(hItemArray, CurItemIndex, &hSound);
MITA_Input_LoadBySound(gInstance, hSound, &hCurItem); //load new source
MITA_Engine_AddSource(hEngine, hCurItem);
MITA_Input_Play(hCurItem, MITA_NULL);
}

Sleep(10);
} while (Key != 27);

_end:
MITA_Engine_DeleteSource(hEngine, hCurItem);
MITA_DeleteSoundArray(hItemArray);
MITA_CloseHandle(hEngine); //Release Engine Object
MITA_CloseHandle(gInstance); //Release global instance handle.
}

#pragma warning(pop)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值