2018-04-21 21:24:46 +08:00
|
|
|
|
#include "..\e2dtool.h"
|
|
|
|
|
|
#include "..\e2dmanager.h"
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
using namespace e2d;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-04-01 23:08:11 +08:00
|
|
|
|
#if HIGHER_THAN_VS2010
|
|
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
#ifndef SAFE_DELETE
|
|
|
|
|
|
#define SAFE_DELETE(p) { if (p) { delete (p); (p)=nullptr; } }
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifndef SAFE_DELETE_ARRAY
|
|
|
|
|
|
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p)=nullptr; } }
|
|
|
|
|
|
#endif
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-28 19:17:15 +08:00
|
|
|
|
inline bool TraceError(wchar_t* sPrompt)
|
2018-02-01 22:07:44 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
WARN_IF(true, "Music error: %s failed!", sPrompt);
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-28 19:17:15 +08:00
|
|
|
|
inline bool TraceError(wchar_t* sPrompt, HRESULT hr)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
WARN_IF(true, "Music error: %s (%#X)", sPrompt, hr);
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
Music::Music()
|
2018-02-01 22:07:44 +08:00
|
|
|
|
: m_bOpened(false)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
, m_bPlaying(false)
|
2018-02-01 22:07:44 +08:00
|
|
|
|
, m_pwfx(nullptr)
|
|
|
|
|
|
, m_hmmio(nullptr)
|
|
|
|
|
|
, m_pResourceBuffer(nullptr)
|
|
|
|
|
|
, m_pbWaveData(nullptr)
|
|
|
|
|
|
, m_dwSize(0)
|
|
|
|
|
|
, m_pSourceVoice(nullptr)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-30 01:41:29 +08:00
|
|
|
|
e2d::Music::Music(String strFileName)
|
2018-03-02 23:49:57 +08:00
|
|
|
|
: m_bOpened(false)
|
|
|
|
|
|
, m_bPlaying(false)
|
|
|
|
|
|
, m_pwfx(nullptr)
|
|
|
|
|
|
, m_hmmio(nullptr)
|
|
|
|
|
|
, m_pResourceBuffer(nullptr)
|
|
|
|
|
|
, m_pbWaveData(nullptr)
|
|
|
|
|
|
, m_dwSize(0)
|
|
|
|
|
|
, m_pSourceVoice(nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
this->open(strFileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
Music::~Music()
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-03-02 23:49:57 +08:00
|
|
|
|
close();
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-30 01:41:29 +08:00
|
|
|
|
bool Music::open(String strFileName)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (m_bOpened)
|
|
|
|
|
|
{
|
2018-04-23 00:05:57 +08:00
|
|
|
|
WARN_IF(true, "Music can be opened only once!");
|
2017-12-08 15:37:52 +08:00
|
|
|
|
return false;
|
2018-02-01 22:07:44 +08:00
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-28 19:17:15 +08:00
|
|
|
|
if (strFileName.isEmpty())
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-04-23 00:05:57 +08:00
|
|
|
|
WARN_IF(true, "Music::open Invalid file name.");
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return false;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
IXAudio2 * pXAudio2 = MusicManager::getIXAudio2();
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (!pXAudio2)
|
|
|
|
|
|
{
|
2018-04-23 00:05:57 +08:00
|
|
|
|
WARN_IF(true, "IXAudio2 nullptr pointer error!");
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20><>λ wave <20>ļ<EFBFBD>
|
|
|
|
|
|
wchar_t strFilePath[MAX_PATH];
|
|
|
|
|
|
if (!_findMediaFileCch(strFilePath, MAX_PATH, strFileName))
|
|
|
|
|
|
{
|
2018-04-23 00:05:57 +08:00
|
|
|
|
WARN_IF(true, "Failed to find media file: %s", (const wchar_t*)strFileName);
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
m_hmmio = mmioOpen(strFilePath, nullptr, MMIO_ALLOCBUF | MMIO_READ);
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (nullptr == m_hmmio)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return TraceError(L"mmioOpen");
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (!_readMMIO())
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1> wave <20>ļ<EFBFBD>ʱ ReadMMIO <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|
|
|
|
|
mmioClose(m_hmmio, 0);
|
|
|
|
|
|
return TraceError(L"_readMMIO");
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (!_resetFile())
|
|
|
|
|
|
return TraceError(L"_resetFile");
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>wave <20>ļ<EFBFBD><C4BC>Ĵ<EFBFBD>С<EFBFBD><D0A1> m_ck.cksize
|
|
|
|
|
|
m_dwSize = m_ck.cksize;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>
|
|
|
|
|
|
m_pbWaveData = new BYTE[m_dwSize];
|
|
|
|
|
|
|
|
|
|
|
|
if (!_read(m_pbWaveData, m_dwSize))
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
TraceError(L"Failed to read WAV data");
|
|
|
|
|
|
SAFE_DELETE_ARRAY(m_pbWaveData);
|
|
|
|
|
|
return false;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
2018-02-01 22:07:44 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
if (FAILED(hr = pXAudio2->CreateSourceVoice(&m_pSourceVoice, m_pwfx)))
|
|
|
|
|
|
{
|
2018-04-23 00:05:57 +08:00
|
|
|
|
TraceError(L"Create source voice error", hr);
|
2018-02-01 22:07:44 +08:00
|
|
|
|
SAFE_DELETE_ARRAY(m_pbWaveData);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_bOpened = true;
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
return true;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool Music::play(int nLoopCount)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-03-02 23:49:57 +08:00
|
|
|
|
if (!m_bOpened)
|
|
|
|
|
|
{
|
|
|
|
|
|
WARN_IF(true, "Music::play Failed: Music must be opened first!");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_pSourceVoice == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
WARN_IF(true, "Music::play Failed: IXAudio2SourceVoice Null pointer exception!");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-02-01 22:07:44 +08:00
|
|
|
|
|
2017-12-08 15:37:52 +08:00
|
|
|
|
if (m_bPlaying)
|
|
|
|
|
|
{
|
|
|
|
|
|
stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-06 21:11:54 +08:00
|
|
|
|
nLoopCount = min(nLoopCount, XAUDIO2_LOOP_INFINITE - 1);
|
|
|
|
|
|
nLoopCount = (nLoopCount < 0) ? XAUDIO2_LOOP_INFINITE : nLoopCount;
|
|
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20>ύ wave <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
XAUDIO2_BUFFER buffer = { 0 };
|
|
|
|
|
|
buffer.pAudioData = m_pbWaveData;
|
|
|
|
|
|
buffer.Flags = XAUDIO2_END_OF_STREAM;
|
|
|
|
|
|
buffer.AudioBytes = m_dwSize;
|
|
|
|
|
|
buffer.LoopCount = nLoopCount;
|
|
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
HRESULT hr;
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (FAILED(hr = m_pSourceVoice->SubmitSourceBuffer(&buffer)))
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-04-23 00:05:57 +08:00
|
|
|
|
TraceError(L"Submitting source buffer error", hr);
|
2018-02-01 22:07:44 +08:00
|
|
|
|
m_pSourceVoice->DestroyVoice();
|
|
|
|
|
|
SAFE_DELETE_ARRAY(m_pbWaveData);
|
|
|
|
|
|
return false;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (SUCCEEDED(hr = m_pSourceVoice->Start(0)))
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bPlaying = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return SUCCEEDED(hr);
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
void Music::pause()
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (m_pSourceVoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SUCCEEDED(m_pSourceVoice->Stop()))
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
void Music::resume()
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (m_pSourceVoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SUCCEEDED(m_pSourceVoice->Start()))
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bPlaying = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
void Music::stop()
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (m_pSourceVoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SUCCEEDED(m_pSourceVoice->Stop()))
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pSourceVoice->ExitLoop();
|
|
|
|
|
|
m_pSourceVoice->FlushSourceBuffers();
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
void Music::close()
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (m_pSourceVoice)
|
2018-03-02 23:49:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_pSourceVoice->Stop();
|
|
|
|
|
|
m_pSourceVoice->FlushSourceBuffers();
|
|
|
|
|
|
m_pSourceVoice->DestroyVoice();
|
|
|
|
|
|
m_pSourceVoice = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_hmmio != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
mmioClose(m_hmmio, 0);
|
|
|
|
|
|
m_hmmio = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SAFE_DELETE_ARRAY(m_pResourceBuffer);
|
|
|
|
|
|
SAFE_DELETE_ARRAY(m_pbWaveData);
|
|
|
|
|
|
SAFE_DELETE_ARRAY(m_pwfx);
|
|
|
|
|
|
|
|
|
|
|
|
m_bOpened = false;
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-04-01 23:08:11 +08:00
|
|
|
|
bool Music::isPlaying() const
|
2018-03-02 23:49:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (m_bOpened && m_pSourceVoice)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
XAUDIO2_VOICE_STATE state;
|
|
|
|
|
|
m_pSourceVoice->GetState(&state);
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (state.BuffersQueued == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return m_bPlaying;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double Music::getVolume() const
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
float fVolume = 0.0f;
|
|
|
|
|
|
if (m_pSourceVoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pSourceVoice->GetVolume(&fVolume);
|
|
|
|
|
|
}
|
2018-02-27 21:07:43 +08:00
|
|
|
|
return static_cast<double>(fVolume);
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
bool Music::setVolume(double fVolume)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (m_pSourceVoice)
|
|
|
|
|
|
{
|
2018-02-27 21:07:43 +08:00
|
|
|
|
return SUCCEEDED(m_pSourceVoice->SetVolume(min(max(static_cast<float>(fVolume), -224), 224)));
|
2018-02-01 22:07:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
double Music::getFrequencyRatio() const
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
float fFrequencyRatio = 0.0f;
|
|
|
|
|
|
if (m_pSourceVoice)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
m_pSourceVoice->GetFrequencyRatio(&fFrequencyRatio);
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
2018-02-27 21:07:43 +08:00
|
|
|
|
return static_cast<double>(fFrequencyRatio);
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
bool Music::setFrequencyRatio(double fFrequencyRatio)
|
2017-12-08 15:37:52 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (m_pSourceVoice)
|
|
|
|
|
|
{
|
|
|
|
|
|
fFrequencyRatio = min(max(fFrequencyRatio, XAUDIO2_MIN_FREQ_RATIO), XAUDIO2_MAX_FREQ_RATIO);
|
2018-02-27 21:07:43 +08:00
|
|
|
|
return SUCCEEDED(m_pSourceVoice->SetFrequencyRatio(static_cast<float>(fFrequencyRatio)));
|
2018-02-01 22:07:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
IXAudio2SourceVoice * Music::getIXAudio2SourceVoice() const
|
2018-02-01 22:07:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
return m_pSourceVoice;
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool Music::_readMMIO()
|
2018-02-01 22:07:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
MMCKINFO ckIn;
|
|
|
|
|
|
PCMWAVEFORMAT pcmWaveFormat;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
memset(&ckIn, 0, sizeof(ckIn));
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
m_pwfx = nullptr;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if ((0 != mmioDescend(m_hmmio, &m_ckRiff, nullptr, 0)))
|
|
|
|
|
|
return TraceError(L"mmioDescend");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// ȷ<><C8B7><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD> wave <20>ļ<EFBFBD>
|
|
|
|
|
|
if ((m_ckRiff.ckid != FOURCC_RIFF) ||
|
|
|
|
|
|
(m_ckRiff.fccType != mmioFOURCC('W', 'A', 'V', 'E')))
|
|
|
|
|
|
return TraceError(L"mmioFOURCC");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>в<EFBFBD><D0B2><EFBFBD> 'fmt' <20><>
|
|
|
|
|
|
ckIn.ckid = mmioFOURCC('f', 'm', 't', ' ');
|
|
|
|
|
|
if (0 != mmioDescend(m_hmmio, &ckIn, &m_ckRiff, MMIO_FINDCHUNK))
|
|
|
|
|
|
return TraceError(L"mmioDescend");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// 'fmt' <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6> PCMWAVEFORMAT һ<><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (ckIn.cksize < (LONG)sizeof(PCMWAVEFORMAT))
|
|
|
|
|
|
return TraceError(L"sizeof(PCMWAVEFORMAT)");
|
|
|
|
|
|
|
|
|
|
|
|
// <20><> 'fmt' <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1> pcmWaveFormat <20><>
|
|
|
|
|
|
if (mmioRead(m_hmmio, (HPSTR)&pcmWaveFormat,
|
|
|
|
|
|
sizeof(pcmWaveFormat)) != sizeof(pcmWaveFormat))
|
|
|
|
|
|
return TraceError(L"mmioRead");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> WAVEFORMATEX<45><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PCM <20><>ʽ<EFBFBD><CABD><EFBFBD>ٶ<EFBFBD>ȡһ<C8A1><D2BB> WORD <20><>С
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݾ<EFBFBD><DDBE>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С
|
|
|
|
|
|
if (pcmWaveFormat.wf.wFormatTag == WAVE_FORMAT_PCM)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
m_pwfx = (WAVEFORMATEX*)new CHAR[sizeof(WAVEFORMATEX)];
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
memcpy(m_pwfx, &pcmWaveFormat, sizeof(pcmWaveFormat));
|
|
|
|
|
|
m_pwfx->cbSize = 0;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
2018-02-01 22:07:44 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĴ<DDB5>С
|
|
|
|
|
|
WORD cbExtraBytes = 0L;
|
|
|
|
|
|
if (mmioRead(m_hmmio, (CHAR*)&cbExtraBytes, sizeof(WORD)) != sizeof(WORD))
|
|
|
|
|
|
return TraceError(L"mmioRead");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
m_pwfx = (WAVEFORMATEX*)new CHAR[sizeof(WAVEFORMATEX) + cbExtraBytes];
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
memcpy(m_pwfx, &pcmWaveFormat, sizeof(pcmWaveFormat));
|
|
|
|
|
|
m_pwfx->cbSize = cbExtraBytes;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (mmioRead(m_hmmio, (CHAR*)(((BYTE*)&(m_pwfx->cbSize)) + sizeof(WORD)),
|
|
|
|
|
|
cbExtraBytes) != cbExtraBytes)
|
|
|
|
|
|
{
|
|
|
|
|
|
SAFE_DELETE(m_pwfx);
|
|
|
|
|
|
return TraceError(L"mmioRead");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (0 != mmioAscend(m_hmmio, &ckIn, 0))
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
SAFE_DELETE(m_pwfx);
|
|
|
|
|
|
return TraceError(L"mmioAscend");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
2018-02-01 22:07:44 +08:00
|
|
|
|
|
|
|
|
|
|
return true;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool Music::_resetFile()
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// Seek to the data
|
|
|
|
|
|
if (-1 == mmioSeek(m_hmmio, m_ckRiff.dwDataOffset + sizeof(FOURCC),
|
|
|
|
|
|
SEEK_SET))
|
|
|
|
|
|
return TraceError(L"mmioSeek");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// Search the input file for the 'data' chunk.
|
|
|
|
|
|
m_ck.ckid = mmioFOURCC('d', 'a', 't', 'a');
|
|
|
|
|
|
if (0 != mmioDescend(m_hmmio, &m_ck, &m_ckRiff, MMIO_FINDCHUNK))
|
|
|
|
|
|
return TraceError(L"mmioDescend");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return true;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
bool Music::_read(BYTE* pBuffer, DWORD dwSizeToRead)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
MMIOINFO mmioinfoIn; // current status of m_hmmio
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (0 != mmioGetInfo(m_hmmio, &mmioinfoIn, 0))
|
|
|
|
|
|
return TraceError(L"mmioGetInfo");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
UINT cbDataIn = dwSizeToRead;
|
|
|
|
|
|
if (cbDataIn > m_ck.cksize)
|
|
|
|
|
|
cbDataIn = m_ck.cksize;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
m_ck.cksize -= cbDataIn;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
for (DWORD cT = 0; cT < cbDataIn; cT++)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Copy the bytes from the io to the buffer.
|
|
|
|
|
|
if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (0 != mmioAdvance(m_hmmio, &mmioinfoIn, MMIO_READ))
|
|
|
|
|
|
return TraceError(L"mmioAdvance");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)
|
|
|
|
|
|
return TraceError(L"mmioinfoIn.pchNext");
|
|
|
|
|
|
}
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// Actual copy.
|
|
|
|
|
|
*((BYTE*)pBuffer + cT) = *((BYTE*)mmioinfoIn.pchNext);
|
|
|
|
|
|
mmioinfoIn.pchNext++;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (0 != mmioSetInfo(m_hmmio, &mmioinfoIn, 0))
|
|
|
|
|
|
return TraceError(L"mmioSetInfo");
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return true;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
bool Music::_findMediaFileCch(wchar_t* strDestPath, int cchDest, const wchar_t * strFilename)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
bool bFound = false;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-03-02 23:49:57 +08:00
|
|
|
|
if (nullptr == strFilename || nullptr == strDestPath || cchDest < 10)
|
2018-02-01 22:07:44 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the exe name, and exe path
|
2018-02-28 19:17:15 +08:00
|
|
|
|
wchar_t strExePath[MAX_PATH] = { 0 };
|
|
|
|
|
|
wchar_t strExeName[MAX_PATH] = { 0 };
|
|
|
|
|
|
wchar_t* strLastSlash = nullptr;
|
2018-02-01 22:07:44 +08:00
|
|
|
|
GetModuleFileName(HINST_THISCOMPONENT, strExePath, MAX_PATH);
|
|
|
|
|
|
strExePath[MAX_PATH - 1] = 0;
|
|
|
|
|
|
strLastSlash = wcsrchr(strExePath, TEXT('\\'));
|
|
|
|
|
|
if (strLastSlash)
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
wcscpy_s(strExeName, MAX_PATH, &strLastSlash[1]);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// Chop the exe name from the exe path
|
|
|
|
|
|
*strLastSlash = 0;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// Chop the .exe from the exe name
|
|
|
|
|
|
strLastSlash = wcsrchr(strExeName, TEXT('.'));
|
|
|
|
|
|
if (strLastSlash)
|
|
|
|
|
|
*strLastSlash = 0;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
wcscpy_s(strDestPath, cchDest, strFilename);
|
|
|
|
|
|
if (GetFileAttributes(strDestPath) != 0xFFFFFFFF)
|
|
|
|
|
|
return true;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
|
2018-02-01 22:07:44 +08:00
|
|
|
|
// Search all parent directories starting at .\ and using strFilename as the leaf name
|
2018-02-28 19:17:15 +08:00
|
|
|
|
wchar_t strLeafName[MAX_PATH] = { 0 };
|
2018-02-01 22:07:44 +08:00
|
|
|
|
wcscpy_s(strLeafName, MAX_PATH, strFilename);
|
|
|
|
|
|
|
2018-02-28 19:17:15 +08:00
|
|
|
|
wchar_t strFullPath[MAX_PATH] = { 0 };
|
|
|
|
|
|
wchar_t strFullFileName[MAX_PATH] = { 0 };
|
|
|
|
|
|
wchar_t strSearch[MAX_PATH] = { 0 };
|
|
|
|
|
|
wchar_t* strFilePart = nullptr;
|
2018-02-01 22:07:44 +08:00
|
|
|
|
|
|
|
|
|
|
GetFullPathName(L".", MAX_PATH, strFullPath, &strFilePart);
|
|
|
|
|
|
if (strFilePart == nullptr)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
while (strFilePart != nullptr && *strFilePart != '\0')
|
2018-01-30 16:45:38 +08:00
|
|
|
|
{
|
2018-02-01 22:07:44 +08:00
|
|
|
|
swprintf_s(strFullFileName, MAX_PATH, L"%s\\%s", strFullPath, strLeafName);
|
|
|
|
|
|
if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF)
|
|
|
|
|
|
{
|
|
|
|
|
|
wcscpy_s(strDestPath, cchDest, strFullFileName);
|
|
|
|
|
|
bFound = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
swprintf_s(strFullFileName, MAX_PATH, L"%s\\%s\\%s", strFullPath, strExeName, strLeafName);
|
|
|
|
|
|
if (GetFileAttributes(strFullFileName) != 0xFFFFFFFF)
|
|
|
|
|
|
{
|
|
|
|
|
|
wcscpy_s(strDestPath, cchDest, strFullFileName);
|
|
|
|
|
|
bFound = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
swprintf_s(strSearch, MAX_PATH, L"%s\\..", strFullPath);
|
|
|
|
|
|
GetFullPathName(strSearch, MAX_PATH, strFullPath, &strFilePart);
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
2018-02-01 22:07:44 +08:00
|
|
|
|
if (bFound)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// ʧ<><CAA7>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>Ϊ·<CEAA><C2B7><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>ͬʱҲ<CAB1><D2B2><EFBFBD>ش<EFBFBD><D8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
wcscpy_s(strDestPath, cchDest, strFilename);
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
2018-01-30 16:45:38 +08:00
|
|
|
|
}
|
2018-04-01 23:08:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Music::Music()
|
|
|
|
|
|
: m_wnd(NULL)
|
|
|
|
|
|
, m_dev(0L)
|
|
|
|
|
|
, m_nMusicID(0)
|
|
|
|
|
|
, m_bPlaying(false)
|
|
|
|
|
|
, m_nRepeatTimes(0)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_wnd = CreateWindowEx(
|
|
|
|
|
|
WS_EX_APPWINDOW,
|
|
|
|
|
|
MUSIC_CLASS_NAME,
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
WS_POPUPWINDOW,
|
|
|
|
|
|
0, 0, 0, 0,
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
MusicManager::getHInstance(),
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (m_wnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetWindowLongPtr(m_wnd, GWLP_USERDATA, (LONG_PTR)this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
e2d::Music::~Music()
|
|
|
|
|
|
{
|
|
|
|
|
|
close();
|
|
|
|
|
|
DestroyWindow(m_wnd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool e2d::Music::open(String pFileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pFileName.isEmpty())
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
|
|
|
|
|
|
|
MCI_OPEN_PARMS mciOpen = { 0 };
|
|
|
|
|
|
mciOpen.lpstrDeviceType = 0;
|
|
|
|
|
|
mciOpen.lpstrElementName = pFileName;
|
|
|
|
|
|
|
|
|
|
|
|
MCIERROR mciError;
|
|
|
|
|
|
mciError = mciSendCommand(
|
|
|
|
|
|
0,
|
|
|
|
|
|
MCI_OPEN,
|
|
|
|
|
|
MCI_OPEN_ELEMENT,
|
|
|
|
|
|
reinterpret_cast<DWORD_PTR>(&mciOpen)
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (mciError == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_dev = mciOpen.wDeviceID;
|
|
|
|
|
|
m_nMusicID = pFileName.getHashCode();
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool e2d::Music::play(int nLoopCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_dev)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MCI_PLAY_PARMS mciPlay = { 0 };
|
|
|
|
|
|
mciPlay.dwCallback = reinterpret_cast<DWORD_PTR>(m_wnd);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
MCIERROR mciError = mciSendCommand(
|
|
|
|
|
|
m_dev,
|
|
|
|
|
|
MCI_PLAY,
|
|
|
|
|
|
MCI_FROM | MCI_NOTIFY,
|
|
|
|
|
|
reinterpret_cast<DWORD_PTR>(&mciPlay)
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!mciError)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bPlaying = true;
|
|
|
|
|
|
m_nRepeatTimes = nLoopCount;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Music::close()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_bPlaying)
|
|
|
|
|
|
{
|
|
|
|
|
|
stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_dev)
|
|
|
|
|
|
{
|
|
|
|
|
|
_sendCommand(MCI_CLOSE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
m_dev = 0;
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Music::pause()
|
|
|
|
|
|
{
|
|
|
|
|
|
_sendCommand(MCI_PAUSE);
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Music::resume()
|
|
|
|
|
|
{
|
|
|
|
|
|
_sendCommand(MCI_RESUME);
|
|
|
|
|
|
m_bPlaying = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Music::stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
_sendCommand(MCI_STOP);
|
|
|
|
|
|
m_bPlaying = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool e2d::Music::isPlaying() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_bPlaying;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Music::getVolume() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Music::setVolume(double fVolume)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double Music::getFrequencyRatio() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Music::setFrequencyRatio(double fFrequencyRatio)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::Music::_sendCommand(int nCommand, DWORD_PTR param1, DWORD_PTR parma2)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>豸ʱ<E8B1B8><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><CEB2><EFBFBD>
|
|
|
|
|
|
if (!m_dev)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD>
|
|
|
|
|
|
mciSendCommand(m_dev, nCommand, param1, parma2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LRESULT WINAPI e2d::Music::MusicProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
|
{
|
|
|
|
|
|
e2d::Music * pPlayer = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (Msg == MM_MCINOTIFY
|
|
|
|
|
|
&& wParam == MCI_NOTIFY_SUCCESSFUL
|
|
|
|
|
|
&& (pPlayer = (Music *)GetWindowLongPtr(hWnd, GWLP_USERDATA)))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pPlayer->m_nRepeatTimes > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
pPlayer->m_nRepeatTimes--;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pPlayer->m_nRepeatTimes)
|
|
|
|
|
|
{
|
|
|
|
|
|
mciSendCommand(static_cast<MCIDEVICEID>(lParam), MCI_SEEK, MCI_SEEK_TO_START, 0);
|
|
|
|
|
|
|
|
|
|
|
|
MCI_PLAY_PARMS mciPlay = { 0 };
|
|
|
|
|
|
mciPlay.dwCallback = reinterpret_cast<DWORD_PTR>(hWnd);
|
|
|
|
|
|
mciSendCommand(static_cast<MCIDEVICEID>(lParam), MCI_PLAY, MCI_NOTIFY, reinterpret_cast<DWORD_PTR>(&mciPlay));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
pPlayer->m_bPlaying = false;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return DefWindowProc(hWnd, Msg, wParam, lParam);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|