📄 playerapp.cpp
字号:
// PlayerApp.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "PlayerApp.h"
#include "PlayerDlg.h"
#include "InfoDlg.h"
#include "VolumeDlg.h"
#include "EqualizerDlg.h"
#include "FeedbackHandler.h"
#include "stream_input.h"
#ifdef MODULES_ENABLE_AAC_CODEC
#include "aac_codec.h"
#endif
#ifdef MODULES_ENABLE_QDMC_CODEC
#include "qdmc_codec.h"
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Globals
CPlayerDlg *PlayerDialog;
/////////////////////////////////////////////////////////////////////////////
// CMfcPlayerApp
BEGIN_MESSAGE_MAP(CPlayerApp, CWinApp)
//{{AFX_MSG_MAP(CPlayerApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPlayerApp construction
CPlayerApp::CPlayerApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CPlayerApp object
CPlayerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CPlayerApp initialization
BOOL CPlayerApp::InitInstance()
{
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
PlayerDialog = new CPlayerDlg;
m_pMainWnd = PlayerDialog;
int nResponse = PlayerDialog->DoModal();
delete PlayerDialog;
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer constructor
SamplePlayer::SamplePlayer(HINSTANCE instance):
XaudioPlayer(instance), m_Scrolling(FALSE), m_State(XA_PLAYER_STATE_STOPPED)
{
#if defined(MODULES_ENABLE_AAC_CODEC)
#if defined(MODULES_CONFIG_AAC_CODEC_LINKAGE_STATIC)
XA_MAKE_SYMBOL_NAME_FROM_STATIC(aac_codec_name, aac_codec_module_register);
CodecModuleRegister(aac_codec_name);
#elif defined(MODULES_CONFIG_AAC_CODEC_LINKAGE_DYNAMIC)
CodecModuleRegister("xa_aac_codec.dll");
#else
#error need to configure AAC codec linkage type
#endif
#endif
#if defined(MODULES_ENABLE_QDMC_CODEC)
#if defined(MODULES_CONFIG_QDMC_CODEC_LINKAGE_STATIC)
XA_MAKE_SYMBOL_NAME_FROM_STATIC(qdmc_codec_name, qdmc_codec_module_register);
CodecModuleRegister(qdmc_codec_name);
#elif defined(MODULES_CONFIG_QDMC_CODEC_LINKAGE_DYNAMIC)
CocdecModuleRegister("xa_qdmc_codec.dll");
#else
#error need to configure QDesign codec linkage type
#endif
#endif
// this is the place to add other module registration calls
// as well as initial player settings
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyReady
void
SamplePlayer::OnNotifyReady()
{
// set some of the player's global options
SetPlayerMode(XA_PLAYER_MODE_OUTPUT_AUTO_CLOSE_ON_STOP);
SetFeedbackAudioEventRate(100);
SetFeedbackHandlerEnvironmentInteger("CLIENT.FEEDBACK-WINDOW",
(long)PlayerDialog->m_FeedbackWindow.m_hWnd);
{
char name[128];
sprintf(name, "function@%08lx", feedback_module_register);
FeedbackHandlerModuleRegister(name);
}
SetFeedbackHandlerName("sample-spectrum");
FeedbackHandlerStart();
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyNack
void
SamplePlayer::OnNotifyNack(XA_NackInfo *info)
{
char message[256];
sprintf(message,"Command %d failed\n[%s]",
info->command,
xaudio_error_string(info->code));
MessageBox(NULL, message, "Xaudio Command Failed", MB_OK | MB_ICONSTOP);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyProgress
void
SamplePlayer::OnNotifyProgress(XA_ProgressInfo *info)
{
switch (info->code) {
case XA_PROGRESS_CODE_STREAM_CONNECTING:
PlayerDialog->m_NetworkStatusLabel.SetWindowText("CONNECTING");
break;
case XA_PROGRESS_CODE_STREAM_CONNECTED:
PlayerDialog->m_NetworkStatusLabel.SetWindowText("CONNECTED");
break;
case XA_PROGRESS_CODE_STREAM_SENDING_REQUEST:
PlayerDialog->m_NetworkStatusLabel.SetWindowText("SENDING REQUEST");
break;
case XA_PROGRESS_CODE_STREAM_BUFFER_UNDERFLOW:
PlayerDialog->m_NetworkStatusLabel.SetWindowText("BUFFER UNDERFLOW");
break;
case XA_PROGRESS_CODE_STREAM_BUFFER_OK:
PlayerDialog->m_NetworkStatusLabel.SetWindowText("BUFFER REFILLED");
PlayerDialog->m_NetworkProgressBar1.SetRange(0, 100);
PlayerDialog->m_NetworkProgressBar1.SetPos(100);
break;
case XA_PROGRESS_CODE_STREAM_PREBUFFER_FULLNESS:
PlayerDialog->m_NetworkProgressBar1.SetRange(0, 100);
PlayerDialog->m_NetworkProgressBar1.SetPos(info->value);
break;
case XA_PROGRESS_CODE_STREAM_BUFFER_FULLNESS:
PlayerDialog->m_NetworkProgressBar2.SetRange(0, 100);
PlayerDialog->m_NetworkProgressBar2.SetPos(info->value);
break;
case XA_PROGRESS_CODE_STREAM_REACHED_EOS:
PlayerDialog->m_NetworkStatusLabel.SetWindowText("END OF STREAM");
}
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyPlayerState
void
SamplePlayer::OnNotifyPlayerState(XA_PlayerState state)
{
CString state_name;
// compute state name
switch (state) {
case XA_PLAYER_STATE_PLAYING:
state_name = "PLAYING";
// change the name of the play button to "Pause"
PlayerDialog->m_PlayButton.SetWindowText("Pause");
break;
case XA_PLAYER_STATE_EOS:
state_name = "EOF";
// close and reopen the input
PlayerDialog->m_Player->InputClose();
PlayerDialog->m_Player->InputOpen(NULL);
break;
case XA_PLAYER_STATE_STOPPED:
state_name = "STOPPED";
// change the name of the play button to "Play"
PlayerDialog->m_PlayButton.SetWindowText("Play");
break;
case XA_PLAYER_STATE_PAUSED:
// if we're sliding the bar, ignore this message
if (m_Scrolling) return;
state_name = "PAUSED";
// change the name of the play button to "Play"
PlayerDialog->m_PlayButton.SetWindowText("Play");
break;
default: return;
}
// remember the state
m_State = state;
// display the current state
PlayerDialog->m_StateLabel.SetWindowText(state_name);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyInputName
void
SamplePlayer::OnNotifyInputName(const char *name)
{
// a file has been openned
PlayerDialog->m_NameLabel.SetWindowText(name);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyInputPosition
void
SamplePlayer::OnNotifyInputPosition(unsigned long offset, unsigned long range)
{
// show position on the slider
PlayerDialog->m_Slider.SetPos(offset);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyInputState
void
SamplePlayer::OnNotifyInputState(XA_InputState state)
{
BOOL enabled;
switch (state) {
case XA_INPUT_STATE_OPEN:
// enable the play and stop buttons, and the slider
enabled = TRUE;
// autoplay
if (PlayerDialog->m_AutoPlayCheckBox.GetCheck()) Play();
break;
case XA_INPUT_STATE_CLOSED:
// disable the play and stop buttons, and the slider
enabled = FALSE;
break;
}
PlayerDialog->m_PlayButton.EnableWindow(enabled);
PlayerDialog->m_StopButton.EnableWindow(enabled);
PlayerDialog->m_Slider.EnableWindow(enabled);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyInputTimecode
void
SamplePlayer::OnNotifyInputTimecode(XA_TimecodeInfo *info)
{
char caption[128];
sprintf(caption, "%02d:%02d:%02d",
info->h,
info->m,
info->s);
PlayerDialog->m_TimecodeLabel.SetWindowText(caption);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyInputModuleInfo
void
SamplePlayer::OnNotifyInputModuleInfo(XA_ModuleInfo *info)
{
if (InfoDialog == NULL) return;
InfoDialog->m_InputList.AddString(info->name);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyOutputState
void
SamplePlayer::OnNotifyOutputState(XA_OutputState state)
{
switch (state) {
case XA_OUTPUT_STATE_OPEN:
// enable the volume button
PlayerDialog->m_VolumeButton.EnableWindow(TRUE);
break;
case XA_INPUT_STATE_CLOSED:
// disable volume button
PlayerDialog->m_VolumeButton.EnableWindow(FALSE);
break;
}
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyOutputModuleInfo
void
SamplePlayer::OnNotifyOutputModuleInfo(XA_ModuleInfo *info)
{
if (InfoDialog == NULL) return;
InfoDialog->m_OutputList.AddString(info->name);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyOutputMasterLevel
void
SamplePlayer::OnNotifyOutputMasterLevel(unsigned char level)
{
if (VolumeDialog == NULL) return;
VolumeDialog->m_MasterSlider.SetPos(level);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyOutputPcmLevel
void
SamplePlayer::OnNotifyOutputPcmLevel(unsigned char level)
{
if (VolumeDialog == NULL) return;
VolumeDialog->m_PcmSlider.SetPos(level);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyOutputBalance
void
SamplePlayer::OnNotifyOutputBalance(unsigned char balance)
{
if (VolumeDialog == NULL) return;
VolumeDialog->m_BalanceSlider.SetPos(balance);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyStreamDuration
void
SamplePlayer::OnNotifyStreamDuration(unsigned long duration)
{
char caption[128];
sprintf(caption, "%d seconds", duration);
PlayerDialog->m_DurationLabel.SetWindowText(caption);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyStreamMimeType
void
SamplePlayer::OnNotifyStreamMimeType(const char *mime_type)
{
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyStreamProperties
void
SamplePlayer::OnNotifyStreamProperties(XA_PropertyList *properties)
{
// remove all property strings
PlayerDialog->m_StreamPropertyList.ResetContent();
// add new properties
for (unsigned int i=0; i<properties->nb_properties; i++) {
char property[256];
switch (properties->properties[i].type) {
case XA_PROPERTY_TYPE_INTEGER:
sprintf(property, "%s: %d",
properties->properties[i].name,
properties->properties[i].value.integer);
break;
case XA_PROPERTY_TYPE_STRING:
sprintf(property, "%s: %s",
properties->properties[i].name,
properties->properties[i].value.string);
break;
default:
continue;
}
PlayerDialog->m_StreamPropertyList.AddString(property);
}
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyStreamParameters
void
SamplePlayer::OnNotifyStreamParameters(XA_StreamParameters *parameters)
{
char caption[128];
sprintf(caption, "STREAM: %d kbps, %d Hz, %s",
parameters->bitrate,
parameters->frequency,
parameters->nb_channels == 1 ? "mono" : "stereo");
PlayerDialog->m_TypeLabel.SetWindowText(caption);
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyCodecEqualizer
void
SamplePlayer::OnNotifyCodecEqualizer(XA_EqualizerInfo *equalizer)
{
if (EqualizerDialog == NULL) return;
// if the equalizer if NULL, it means it's disabled
if (equalizer == NULL) {
EqualizerDialog->m_EnableEQCheckBox.SetCheck(FALSE);
} else {
EqualizerDialog->m_EnableEQCheckBox.SetCheck(TRUE);
// set the slider positions
EqualizerDialog->m_Slider1.SetPos(-equalizer->left[ 0]);
EqualizerDialog->m_Slider2.SetPos(-equalizer->left[ 1]);
EqualizerDialog->m_Slider3.SetPos(-equalizer->left[ 2]);
EqualizerDialog->m_Slider4.SetPos(-equalizer->left[ 4]);
EqualizerDialog->m_Slider5.SetPos(-equalizer->left[ 6]);
EqualizerDialog->m_Slider6.SetPos(-equalizer->left[ 8]);
EqualizerDialog->m_Slider7.SetPos(-equalizer->left[14]);
EqualizerDialog->m_Slider8.SetPos(-equalizer->left[20]);
}
}
/////////////////////////////////////////////////////////////////////////////
// SamplePlayer::OnNotifyCodecModuleInfo
void
SamplePlayer::OnNotifyCodecModuleInfo(XA_ModuleInfo *info)
{
if (InfoDialog == NULL) return;
InfoDialog->m_CodecList.AddString(info->name);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -