📄 pocketmp3dlg.cpp
字号:
pThis->maplay_Exit(1);
mtx_unlock(mutex);
return 0;
}
if (maplay_args->position_change) {
(pThis->buffer)->clear_buffer();
if (!header->stream_seek(stream, maplay_args->desired_position)) {
pThis->maplay_Exit(0);
mtx_unlock(mutex);
return 1;
}
maplay_args->position_change = false;
pThis->filter1->reset();
if ((which_channels == both) && (mode != single_channel))
pThis->filter2->reset();
if (pThis->l3decoder)
pThis->l3decoder->seek_notify();
// notify the parent of the current position
#ifdef WIN32GUI
pThis->PostMessage(SEEK_ACK, NULL, NULL);
pThis->PostMessage(SCROLL_POS, stream->current_frame(), 0);
#else
#endif // WIN32GUI
}
// Send notification to the scroll bar every 16 frames
{
int32 cf = stream->current_frame();
if (!(cf & 0xf) && !(maplay_args->stop)) {
// Notify the parent of the current position
(pThis->m_ctlSlider).PostMessage(TBM_SETPOS, TRUE, cf);//刷新轨道条的位置
}
mtx_unlock(mutex);
}
#endif // SEEK_STOP
// is there a change in important parameters?
// (bitrate switching is allowed)
if (header->layer() != layer)
{
// layer switching is allowed
if (header->layer() == 3) {
pThis->l3decoder = new LayerIII_Decoder(stream, header,
pThis->filter1, pThis->filter2,
pThis->buffer, which_channels);
} else if (layer == 3) {
delete pThis->l3decoder;
pThis->l3decoder = NULL;
}
layer = header->layer();
}
if (layer != 3) {
Subband *subbands[32];
uint32 num_subbands = header->number_of_subbands();
uint32 i;
mode = header->mode();
// create subband objects:
if (layer == 1)
{
if (mode == single_channel)
for (i = 0; i < num_subbands; ++i)
subbands[i] = new SubbandLayer1(i);
else if (mode == joint_stereo) {
for (i = 0; i < header->intensity_stereo_bound(); ++i)
subbands[i] = new SubbandLayer1Stereo(i);
for (; i < num_subbands; ++i)
subbands[i] = new SubbandLayer1IntensityStereo(i);
} else {
for (i = 0; i < num_subbands; ++i)
subbands[i] = new SubbandLayer1Stereo(i);
}
} else { // Layer II
if (mode == single_channel)
for (i = 0; i < num_subbands; ++i)
subbands[i] = new SubbandLayer2(i);
else if (mode == joint_stereo)
{
for (i = 0; i < header->intensity_stereo_bound(); ++i)
subbands[i] = new SubbandLayer2Stereo(i);
for (; i < num_subbands; ++i)
subbands[i] = new SubbandLayer2IntensityStereo(i);
} else {
for (i = 0; i < num_subbands; ++i)
subbands[i] = new SubbandLayer2Stereo(i);
}
}
// start to read audio data:
for (i = 0; i < num_subbands; ++i)
subbands[i]->read_allocation(stream, header, crc);
if (layer == 2)
for (i = 0; i < num_subbands; ++i)
((SubbandLayer2 *)subbands[i])->read_scalefactor_selection(stream,
crc);
if (!crc || header->checksum_ok())
{
// no checksums or checksum ok, continue reading from stream:
for (i = 0; i < num_subbands; ++i)
subbands[i]->read_scalefactor(stream, header);
do
{
for (i = 0; i < num_subbands; ++i)
read_ready = subbands[i]->read_sampledata(stream);
do
{
for (i = 0; i < num_subbands; ++i)
write_ready = subbands[i]->put_next_sample(which_channels,
pThis->filter1, pThis->filter2);
(pThis->filter1)->calculate_pcm_samples(pThis->buffer);
if ((which_channels == both) && (mode != single_channel))
(pThis->filter2)->calculate_pcm_samples(pThis->buffer);
} while (!write_ready);
} while (!read_ready);
(pThis->buffer)->write_buffer(1);
} // checksum ok
// Jeff : Don't let user know if crc violated.
// else
// Sh*t! Wrong crc checksum in frame!
// cerr << "WARNING: frame contains wrong crc checksum! (throwing frame away)\n";
for (i = 0; i < num_subbands; ++i)
delete subbands[i];
} else { // Layer III
(pThis->l3decoder)->decode();
}
}
while (header->read_header(stream, &crc));
maplay_args->done = true;
PreReturnCleanup:
#ifdef SEEK_STOP
mtx_lock(mutex);
if (!maplay_args->stop) {
// notify the parent of the last frame
(pThis->m_ctlSlider).PostMessage(TBM_SETPOS, TRUE, stream->current_frame());
}
#endif // SEEK_STOP
if(maplay_args->stop)
pThis->maplay_Exit(1);
else
pThis->maplay_Exit(0);
#ifdef SEEK_STOP
if (!maplay_args->stop) {
// tell the parent that we are done
pThis->PostMessage(WM_THREADEND, NULL, NULL);
}
mtx_unlock(mutex);
#endif // SEEK_STOP
return 0;
}
void CPocketMP3Dlg::OnBtnplay()
{
if(m_strName==_T(""))
{
MessageBox(_T("请输入MP3文件名"),_T("提示"),MB_OK);
return;
}
m_ctlBtnOpen.EnableWindow(TRUE);
m_ctlBtnPlay.EnableWindow(FALSE);
m_ctlBtnPause.EnableWindow(TRUE);
m_ctlBtnStop.EnableWindow(TRUE);
m_ctlStatus.SetWindowText(_T("播放..."));
//复位线程退出事件
ResetEvent(exitMPEG_Thread);
if(playing)
{
//这种情况对应在一个文件正在播放时又重新点击“打开”选择新的MP3文件来播放
//发送线程退出事件
maplay_args->stop = true;
playing=false;
paused=false;
SetEvent(exitMPEG_Thread);
Sleep(1000);
ReleaseMutex(maplay_args->mutex);
delete maplay_args->stream;
maplay_args->stream = NULL;
delete maplay_args->MPEGheader;
maplay_args->MPEGheader = NULL;
if (maplay_args->mutex)
{
CloseHandle(maplay_args->mutex);
maplay_args->mutex = NULL;
}
m_ctlSlider.SetPos(0);
reinit_MPEG();//初始化解码过程中使用的变量
//scroll_range = maplay_args->MPEGheader->min_number_of_frames(maplay_args->stream);
m_ctlSlider.SetRange(0,scroll_range);
playing = TRUE;
paused = FALSE;
MPEG_play();
}
else{
if (paused && MPEG_Thread) {
//这种情况对应于暂停后再点击“播放”按扭
playing = TRUE;
paused = FALSE;
waveOutRestart(*phwo);
ResumeThread(MPEG_Thread);
playing = TRUE;
paused = FALSE;
}
else {
//这种情况对应从头播放
reinit_MPEG();//初始化解码过程中使用的变量
//scroll_range = maplay_args->MPEGheader->min_number_of_frames(maplay_args->stream);
m_ctlSlider.SetRange(0,scroll_range);
m_ctlSlider.SetPos(0);
playing = TRUE;
paused = FALSE;
MPEG_play();
}
}
}
bool CPocketMP3Dlg::MPEG_play()
{
m_ctlBtnOpen.EnableWindow(TRUE);
m_ctlBtnPlay.EnableWindow(FALSE);
m_ctlBtnPause.EnableWindow(TRUE);
m_ctlBtnStop.EnableWindow(TRUE);
maplay_args->stop = false;
playing=true;
paused=false;
//创建播放线程
MPEG_Thread=::AfxBeginThread(maplay,(LPVOID)this, THREAD_PRIORITY_HIGHEST);
m_ctlStatus.SetWindowText(_T("播放..."));
m_ctlEditName.EnableWindow(FALSE);
if(MPEG_Thread!=NULL)
return 1;
else
return 0;
}
void CPocketMP3Dlg::OnBtnopen()
{
m_ctlEditName.EnableWindow(TRUE);
m_ctlStatus.SetWindowText(_T(""));
CFileDialog dlg(TRUE,_T(".mp3"),_T("test.mp3"),OFN_HIDEREADONLY,_T("MP3 files(*.mp3)|*.mp3|All Files(*.*)|*.*||"),NULL);
if(dlg.DoModal()==IDOK)
{
m_strName=dlg.GetPathName();
}
UpdateData(FALSE);
if(playing)
{
m_ctlBtnPlay.EnableWindow(TRUE);
}
}
void CPocketMP3Dlg::OnBtnpause()
{
m_ctlBtnOpen.EnableWindow(FALSE);
m_ctlBtnPlay.EnableWindow(TRUE);
m_ctlBtnPause.EnableWindow(FALSE);
m_ctlBtnStop.EnableWindow(FALSE);
paused=true;
playing=false;
SuspendThread(MPEG_Thread);
waveOutPause(*phwo);
m_ctlStatus.SetWindowText(_T("暂停..."));
}
void CPocketMP3Dlg::OnBtnstop()
{
m_ctlEditName.EnableWindow(TRUE);
m_ctlBtnOpen.EnableWindow(TRUE);
m_ctlBtnPlay.EnableWindow(TRUE);
m_ctlBtnPause.EnableWindow(FALSE);
m_ctlBtnStop.EnableWindow(FALSE);
maplay_args->stop = true;
playing=false;
paused=false;
//发送线程退出事件
SetEvent(exitMPEG_Thread);
Sleep(1000);
m_ctlSlider.SetPos(0);
ReleaseMutex(maplay_args->mutex);
delete maplay_args->stream;
maplay_args->stream = NULL;
delete maplay_args->MPEGheader;
maplay_args->MPEGheader = NULL;
if (maplay_args->mutex)
{
CloseHandle(maplay_args->mutex);
maplay_args->mutex = NULL;
}
//WaitForSingleObject(maplay_Exit_done,INFINITE);
m_ctlStatus.SetWindowText(_T("停止..."));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -