BOOL TinyWavePlayer::Play(BOOL bLoop) { do { bPlaying = TRUE; dwBlockOut = dwBlockNext = 0; dwSizeL = waveFile.GetDataSize(); PlayData();//播放数据 if (waveOut.Restart() != MMSYSERR_NOERROR) return FALSE; while (dwBlockOut > 0) { MSG msg = { 0 }; if (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE) && (msg.message == PLAY_QUIT)) { //收到窗口退出消息 bPlaying = FALSE; do { LoopEmpty(); } while (IsPlaying()); waveOut.Reset(); while (dwBlocks > 0) { --dwBlocks; waveOut.Unprepare(audioBlockPtr[dwBlocks]); LocalFree((LPBYTE)audioBlockPtr[dwBlocks]); } waveOut.Close(); waveFile.Close(); break; } } } while (bLoop); return TRUE; }
void TinyWavePlayer::PlayDone(LPWAVEHDR wp, DWORD_PTR dwInstance) { if (wp->dwFlags & WHDR_DONE) { --dwBlockOut; PlayData(); } }
/** * * DigitalPlayback * @param aNumSamples * @param aFilename * @param aDataType * @result TVerdict * */ TVerdict CTestStepSDevSoundPlayEOFPCM16::DigitalPlayback(TInt aNumSamples, TDesC& aFilename, TFourCC& aDataType) { TVerdict initializeOK = InitializeDevSound(aDataType, EMMFStatePlaying); if (initializeOK != EPass) { return EInconclusive; } SetVolume(iMMFDevSound->MaxVolume()); //Get a buffer to fill initializeOK = PlayInit(); if (initializeOK != EPass) { return EInconclusive; } TInt error = iFs.Connect(); if (error != KErrNone) { ERR_PRINTF2 (_L("Could not connect to Filesystem. Error is %d"), error); return EInconclusive; } TInt err = iFile.Open(iFs, aFilename, EFileRead); if (err != KErrNone) { ERR_PRINTF2 (_L("Could not open input file. Error is %d"), err); return EInconclusive; } TInt bufferCount = 0; if (aNumSamples < 0) {// Play to EOF while (initializeOK == KErrNone && iCallbackError == KErrNone) { //read sizeof buffer from file CMMFDataBuffer* buffer = STATIC_CAST (CMMFDataBuffer*, iBuffer); iFile.Read(buffer->Data()); if (buffer->Data().Length()!= buffer->RequestSize()) { INFO_PRINTF3(_L("Data length copied from file = %d. Expected %d. Must be EOF"), buffer->Data().Length(), buffer->RequestSize()); iBuffer->SetLastBuffer(ETrue); } //DevSound Play initializeOK = PlayData(); bufferCount ++; } } else { while (bufferCount < aNumSamples && initializeOK == KErrNone && iCallbackError == KErrNone)
int audioEventPlayData(int eventId, int wParam, int lParam) { // printf("###play cb\n"); PlayData(((LPWAVEHDR)lParam)->dwUser); return 0; }