線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2734
推到 Plurk!
推到 Facebook!

利用mediaplayer做播放器,如何調整音量大小呢?

尚未結案
sb055665
一般會員


發表:24
回覆:25
積分:14
註冊:2006-07-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-08-03 18:33:37 IP:211.20.xxx.xxx 未訂閱

如題,請各位幫幫忙…

還有一個問題,在論壇上看到很多關於Directxshow這個東西來做播放器

如果我要使用這個元件的話,請問這要去那下載,或有人可以提供給我嗎?

kenlee1109
初階會員


發表:20
回覆:40
積分:27
註冊:2006-08-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-08-24 21:50:38 IP:61.229.xxx.xxx 未訂閱

我是以 TrackBar 為調整大小聲的元件,程式啟動時將音效卡的喇叭值讀入並指定給 TrackBar的 Position(Max=32767),很簡單.

在 Initial 時,加入.

m_MixerControl = new CMixerControl(this->Handle);
m_MixerControl->EnableDevice(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE,
MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, 0);

m_MixerControl->GetVolumeRange(&min, &max, 0, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
BeepMax = max;
m_MixerControl->GetCurrentVolume(&pos, 0, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
BeepVolumnTrackBar->Position = pos * BeepVolumnTrackBar->Max / BeepMax;

//---------------------------------------------------------------------------
void __fastcall TMainForm::BeepVolumnOnChange(TObject *Sender){
int pos;

pos = BeepVolumnTrackBar->Position * BeepMax / BeepVolumnTrackBar->Max;
m_MixerControl->SetVolume(pos,0,MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
}

MixerControl.h

#include
#include
#include
#include
#include
#include
#include


class CMixerControl{
private:
HWND m_hWnd;
HMIXER m_hMixer;
char m_MessageBuffer[256];
char m_DeviceName[128];
DWORD m_Destinations;
UINT m_MxId;
BOOL GetDetailValue(DWORD *dwMinimisze, DWORD *dwMaximize, MIXERLINE mxLine);
BOOL GetDetailValue(DWORD *dwVolume, MIXERLINE mxLine);
BOOL SetDetailValue(DWORD dwVolume, DWORD dwControlType, MIXERLINE mxLine);
BOOL EnableDstDevice(DWORD dwDestinationType, BOOL bStatus);
BOOL EnableSrcDevice(DWORD dwSourceType, MIXERLINE mxLine, BOOL bStatus);
BOOL CheckControlType(MIXERLINE mxLine, DWORD dwControlType);
UINT GetSrcIndexFromDst(MIXERLINE mxLine, DWORD dwSourceType, DWORD dwDstControlType);
BOOL EnableSrcFromDst(MIXERLINE mxLine, UINT index, DWORD dwControlType, BOOL bStatus);

public:
CMixerControl(HWND hWnd);
~CMixerControl();
char *GetMixerName();
BOOL GetVolumeRange(DWORD *dwMinimisze, DWORD *dwMaximize, DWORD dwSourceType, DWORD dwDestinationType);
BOOL GetCurrentVolume(DWORD *dwVolume, DWORD dwSourceType, DWORD dwDestinationType);
BOOL SetVolume(DWORD dwVolume, DWORD dwSourceType, DWORD dwDestinationType);
BOOL EnableDevice(DWORD dwSourceType, DWORD dwDestinationType, BOOL bStatus);
BOOL EnableAllDevice(DWORD dwDestinationType, BOOL bStatus);
BOOL SetMixerValue(DWORD dwValue, DWORD dwControlType, DWORD dwSourceType, DWORD dwDestinationType);
BOOL GetComponentName(char *szComponentName, DWORD dwSourceType, DWORD dwDestinationType);
};

#endif

MixerControl.cpp

#include "mixercontrol.h"
#define _DEBUG

//Constructor & Destructor
CMixerControl::CMixerControl(HWND hWnd)
{
MMRESULT mmr;
MIXERCAPS mxcaps;

//Initial Value
m_hWnd = hWnd;
m_hMixer = NULL;
m_MxId = 0;

//Detect audio device
if (mixerGetNumDevs() == 0){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "Could not detect audio device!\nLine : %d\nFile : %s", __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Dectect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return;
}

//Get audio device
mmr = mixerGetDevCaps(m_MxId, &mxcaps, sizeof(mxcaps));
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetDevCaps() failed on m_MxId=%u, mmr=%u!\nLine : %d\nFile : %s", m_MxId, mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return;
}

mmr = mixerOpen(&m_hMixer, m_MxId, (DWORD)(UINT)m_hWnd, 0L, CALLBACK_WINDOW);
if (mmr != MMSYSERR_NOERROR){
m_hMixer = NULL;
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetDevCaps() failed on m_MxId=%u, mmr=%u!\nLine : %d\nFile : %s", m_MxId, mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return;
}
sprintf(m_DeviceName, mxcaps.szPname);
m_Destinations = mxcaps.cDestinations;
}

CMixerControl::~CMixerControl()
{
if (m_hMixer != NULL){
mixerClose(m_hMixer);
}

}

//Return Mixer Name
char *CMixerControl::GetMixerName()
{
return m_DeviceName;
}

//Get the range of the component
BOOL CMixerControl::GetVolumeRange(DWORD *dwMinimize, DWORD *dwMaximize, DWORD dwSourceType, DWORD dwDestinationType)
{
MIXERLINE mxLine;
UINT i, j;
MMRESULT mmr;
DWORD dwConnections;

//Initial value
mxLine.cbStruct = sizeof(mxLine);

//Get Destnation Volume Range
if (dwSourceType == 0){
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
return GetDetailValue(dwMinimize, dwMaximize, mxLine);
}
}
}
else{ //Get Source Volume Range
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
dwConnections = mxLine.cConnections;
for (j = 0; j < dwConnections; j ){
mxLine.cbStruct = sizeof(mxLine);
mxLine.dwSource = j;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_SOURCE);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwSourceType){
return GetDetailValue(dwMinimize, dwMaximize, mxLine);
}
}
}
}
}
return FALSE;
}

BOOL CMixerControl::GetDetailValue(DWORD *dwMinimize, DWORD *dwMaximize, MIXERLINE mxLine)
{
MIXERLINECONTROLS mixerLineControls;
PMIXERCONTROL pMixerControl;
MMRESULT mmr;
UINT i;

//Initial value
pMixerControl = (PMIXERCONTROL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MIXERCONTROL)*mxLine.cControls);
mixerLineControls.cbStruct = sizeof(mixerLineControls);
mixerLineControls.dwLineID = mxLine.dwLineID;
mixerLineControls.dwControlID = m_MxId;
mixerLineControls.cControls = mxLine.cControls;
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControls.pamxctrl = pMixerControl;
//Get mixer line contrls
mmr = mixerGetLineControls((HMIXEROBJ) m_hMixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}
for (i = 0; i < mixerLineControls.cControls; i ){
if (pMixerControl[i].dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME){
*dwMinimize = pMixerControl[i].Bounds.dwMinimum;
*dwMaximize = pMixerControl[i].Bounds.dwMaximum;
HeapFree(GetProcessHeap(), 0, pMixerControl);
return TRUE;
}
}
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}

BOOL CMixerControl::GetCurrentVolume(DWORD *dwVolume, DWORD dwSourceType, DWORD dwDestinationType){
MIXERLINE mxLine;
UINT i, j;
MMRESULT mmr;
DWORD dwConnections;

//Initial value
mxLine.cbStruct = sizeof(mxLine);
if (dwSourceType == 0){
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
//Get mixer line info
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUF
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
return GetDetailValue(dwVolume, mxLine);
}
}
}
else{
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
dwConnections = mxLine.cConnections;
for (j = 0; j < dwConnections; j ){
mxLine.cbStruct = sizeof(mxLine);
mxLine.dwSource = j;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_SOURCE);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwSourceType){
return GetDetailValue(dwVolume, mxLine);
}
}
}
}
}
return FALSE;
}

BOOL CMixerControl::GetDetailValue(DWORD *dwVolume, MIXERLINE mxLine)
{
MIXERLINECONTROLS mixerLineControls;
PMIXERCONTROL pMixerControl;
MIXERCONTROLDETAILS mixerControlDetails;
MIXERCONTROLDETAILS_UNSIGNED mcdu;
MMRESULT mmr;
UINT i;

//Initial value
pMixerControl = (PMIXERCONTROL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MIXERCONTROL)*mxLine.cControls);
mixerLineControls.cbStruct = sizeof(mixerLineControls);
mixerLineControls.dwLineID = mxLine.dwLineID;
mixerLineControls.dwControlID = m_MxId;
mixerLineControls.cControls = mxLine.cControls;
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControls.pamxctrl = pMixerControl;
//Get mixer line controls
mmr = mixerGetLineControls((HMIXEROBJ) m_hMixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
if (mmr != MMSYSERR_NOERROR){
HeapFree(GetProcessHeap(), 0, pMixerControl);
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
for (i = 0; i < mixerLineControls.cControls; i ){
if (pMixerControl[i].dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME){
mixerControlDetails.cbStruct = sizeof(mixerControlDetails);
mixerControlDetails.dwControlID = pMixerControl[i].dwControlID;
mixerControlDetails.cMultipleItems = pMixerControl[i].cMultipleItems;
mixerControlDetails.cChannels = 1;
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mixerControlDetails.paDetails = &mcdu;
//Get mixer control details
mmr = mixerGetControlDetails((HMIXEROBJ) m_hMixer, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE);
if (mmr != MMSYSERR_NOERROR){
HeapFree(GetProcessHeap(), 0, pMixerControl);
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetControlDetails() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
*dwVolume = mcdu.dwValue;
HeapFree(GetProcessHeap(), 0, pMixerControl);
return TRUE;
}
}
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}

BOOL CMixerControl::SetVolume(DWORD dwVolume,DWORD dwSourceType, DWORD dwDestinationType)
{
MIXERLINE mxLine;
UINT i, j;
MMRESULT mmr;
DWORD dwConnections;

//Initial value
mxLine.cbStruct = sizeof(mxLine);

//Get Destnation Volume Range
if (dwSourceType == 0){
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
//Get mixer line info
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
return SetDetailValue(dwVolume, MIXERCONTROL_CONTROLTYPE_VOLUME, mxLine);
}
}
}
else{
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
//Get mixer line info
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
dwConnections = mxLine.cConnections;
for (j = 0; j < dwConnections; j ){
mxLine.cbStruct = sizeof(mxLine);
mxLine.dwSource = j;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_SOURCE);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwSourceType){
return SetDetailValue(dwVolume, MIXERCONTROL_CONTROLTYPE_VOLUME, mxLine);
}
}
}
}
}
return FALSE;
}

BOOL CMixerControl::SetDetailValue(DWORD dwValue, DWORD dwControltype, MIXERLINE mxLine)
{
MIXERLINECONTROLS mixerLineControls;
PMIXERCONTROL pMixerControl;
MIXERCONTROLDETAILS mixerControlDetails;
MIXERCONTROLDETAILS_UNSIGNED mcdu;
MMRESULT mmr;
UINT i;

//Initial mixer line contrls
pMixerControl = (PMIXERCONTROL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MIXERCONTROL)*mxLine.cControls);
mixerLineControls.cbStruct = sizeof(mixerLineControls);
mixerLineControls.dwLineID = mxLine.dwLineID;
mixerLineControls.dwControlID = m_MxId;
mixerLineControls.cControls = mxLine.cControls;
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControls.pamxctrl = pMixerControl;

//Get mixer line controls
mmr = mixerGetLineControls((HMIXEROBJ) m_hMixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
if (mmr != MMSYSERR_NOERROR){
HeapFree(GetProcessHeap(), 0, pMixerControl);
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
for (i = 0; i < mixerLineControls.cControls; i ){
if (pMixerControl[i].dwControlType == dwControltype){
//Initial mixer control details
mixerControlDetails.cbStruct = sizeof(mixerControlDetails);
mixerControlDetails.dwControlID = pMixerControl[i].dwControlID;
mixerControlDetails.cMultipleItems = pMixerControl[i].cMultipleItems;
mixerControlDetails.cChannels = 1;
mixerControlDetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);
mixerControlDetails.paDetails = &mcdu;
mcdu.dwValue = dwValue;
//Set mixer control details
mmr = mixerSetControlDetails((HMIXEROBJ) m_hMixer, &mixerControlDetails, 0L);
if (mmr != MMSYSERR_NOERROR){
HeapFree(GetProcessHeap(), 0, pMixerControl);
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerSetControlDetails() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
HeapFree(GetProcessHeap(), 0, pMixerControl);
return TRUE;
}
}
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}

BOOL CMixerControl::EnableDevice(DWORD dwSourceType, DWORD dwDestinationType, BOOL bStatus)
{
MIXERLINE mxLine;
UINT i;
MMRESULT mmr;

if (dwSourceType == 0){
return EnableDstDevice(dwDestinationType, bStatus);
}
else{
mxLine.cbStruct = sizeof(mxLine);
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
return EnableSrcDevice(dwSourceType, mxLine, bStatus);
}
}
}
return FALSE;
}

BOOL CMixerControl::EnableDstDevice(DWORD dwDestinationType, BOOL bStatus)
{
MIXERLINE mxLine;
UINT i;
MMRESULT mmr;

//Initial Value
mxLine.cbStruct = sizeof(mxLine);
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
if (bStatus == FALSE)
return SetDetailValue(1, MIXERCONTROL_CONTROLTYPE_MUTE, mxLine);
else
return SetDetailValue(0, MIXERCONTROL_CONTROLTYPE_MUTE, mxLine);
}
}
return FALSE;
}

BOOL CMixerControl::EnableSrcDevice(DWORD dwSourceType, MIXERLINE mxLine, BOOL bStatus)
{
UINT index, i;
MIXERLINE mixerline;
MMRESULT mmr;

if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_SINGLESELECT) == TRUE){
index = GetSrcIndexFromDst(mxLine, dwSourceType, MIXERCONTROL_CONTROLTYPE_SINGLESELECT);
if (index == -1)
return FALSE;
return EnableSrcFromDst(mxLine, index, MIXERCONTROL_CONTROLTYPE_SINGLESELECT, bStatus);
}
if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT) == TRUE){
index = GetSrcIndexFromDst(mxLine, dwSourceType, MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT);
if (index == -1)
return FALSE;
return EnableSrcFromDst(mxLine, index, MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT, bStatus);
}
if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_MUX) == TRUE){
index = GetSrcIndexFromDst(mxLine, dwSourceType, MIXERCONTROL_CONTROLTYPE_MUX);
if (index == -1)
return FALSE;
return EnableSrcFromDst(mxLine, index, MIXERCONTROL_CONTROLTYPE_MUX, bStatus);
}
if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_MIXER) == TRUE){
index = GetSrcIndexFromDst(mxLine, dwSourceType, MIXERCONTROL_CONTROLTYPE_MIXER);
if (index == -1)
return FALSE;
return EnableSrcFromDst(mxLine, index, MIXERCONTROL_CONTROLTYPE_MIXER, bStatus);
}

for (i = 0; i < mxLine.cConnections; i ){
mixerline.dwDestination = mxLine.dwDestination;
mixerline.cbStruct = sizeof(mixerline);
mixerline.dwSource = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mixerline, MIXER_GETLINEINFOF_SOURCE);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}

if (mixerline.dwComponentType == dwSourceType){
if (bStatus == FALSE)
return SetDetailValue(1, MIXERCONTROL_CONTROLTYPE_MUTE, mixerline);
else
return SetDetailValue(0, MIXERCONTROL_CONTROLTYPE_MUTE, mixerline);
}
}
return FALSE;
}

BOOL CMixerControl::CheckControlType(MIXERLINE mxLine, DWORD dwControlType)
{
MIXERLINECONTROLS mixerLineControls;
PMIXERCONTROL pMixerControl;
MMRESULT mmr;
UINT i;

//Initial value
pMixerControl = (PMIXERCONTROL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MIXERCONTROL)*mxLine.cControls);
mixerLineControls.cbStruct = sizeof(mixerLineControls);
mixerLineControls.dwLineID = mxLine.dwLineID;
mixerLineControls.dwControlID = m_MxId;
mixerLineControls.cControls = mxLine.cControls;
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControls.pamxctrl = pMixerControl;
mmr = mixerGetLineControls((HMIXEROBJ) m_hMixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}

for (i = 0; i < mixerLineControls.cControls; i ){
if (pMixerControl[i].dwControlType == dwControlType){
HeapFree(GetProcessHeap(), 0, pMixerControl);
return TRUE;
}
}
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}

UINT CMixerControl::GetSrcIndexFromDst(MIXERLINE mxLine, DWORD dwSourceType, DWORD dwDstControlType)
{
MIXERLINECONTROLS mixerLineControls;
PMIXERCONTROL pMixerControl;
MMRESULT mmr;
UINT i, j;

//Initial value
pMixerControl = (PMIXERCONTROL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MIXERCONTROL)*mxLine.cControls);
mixerLineControls.cbStruct = sizeof(mixerLineControls);
mixerLineControls.dwLineID = mxLine.dwLineID;
mixerLineControls.dwControlID = m_MxId;
mixerLineControls.cControls = mxLine.cControls;
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControls.pamxctrl = pMixerControl;
mmr = mixerGetLineControls((HMIXEROBJ) m_hMixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
HeapFree(GetProcessHeap(), 0, pMixerControl);
return -1;
}

for (i = 0; i < mixerLineControls.cControls; i ){
if (pMixerControl[i].dwControlType == dwDstControlType){
MIXERCONTROLDETAILS mixerControlDetails;
PMIXERCONTROLDETAILS_LISTTEXT pmxcd_lt;

pmxcd_lt = (PMIXERCONTROLDETAILS_LISTTEXT)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pMixerControl[i].cMultipleItems * sizeof(MIXERCONTROLDETAILS_LISTTEXT));
mixerControlDetails.cbStruct = sizeof(mixerControlDetails);
mixerControlDetails.dwControlID = pMixerControl[i].dwControlID;
mixerControlDetails.cMultipleItems = pMixerControl[i].cMultipleItems;
mixerControlDetails.cChannels = 1;
mixerControlDetails.cbDetails = sizeof(*pmxcd_lt);
mixerControlDetails.paDetails = pmxcd_lt;
mmr = mixerGetControlDetails((HMIXEROBJ) m_hMixer, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_LISTTEXT );
if (mmr != MMSYSERR_NOERROR){
HeapFree(GetProcessHeap(), 0, pmxcd_lt);
HeapFree(GetProcessHeap(), 0, pMixerControl);
return -1;
}
for (j = 0; j < mixerControlDetails.cMultipleItems; j ){
if (pmxcd_lt[j].dwParam1 == dwSourceType ||
pmxcd_lt[j].dwParam2 == dwSourceType){

HeapFree(GetProcessHeap(), 0, pmxcd_lt);
HeapFree(GetProcessHeap(), 0, pMixerControl);
return j;
}
}
}
}
HeapFree(GetProcessHeap(), 0, pMixerControl);
return -1;
}

BOOL CMixerControl::EnableSrcFromDst(MIXERLINE mxLine, UINT index, DWORD dwControlType, BOOL bStatus)
{
MIXERLINECONTROLS mixerLineControls;
PMIXERCONTROL pMixerControl;
MMRESULT mmr;
UINT i, j;

//Initial value
pMixerControl = (PMIXERCONTROL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MIXERCONTROL)*mxLine.cControls);
mixerLineControls.cbStruct = sizeof(mixerLineControls);
mixerLineControls.dwLineID = mxLine.dwLineID;
mixerLineControls.dwControlID = m_MxId;
mixerLineControls.cControls = mxLine.cControls;
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControls.pamxctrl = pMixerControl;
mmr = mixerGetLineControls((HMIXEROBJ) m_hMixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}

for (i = 0; i < mixerLineControls.cControls; i ){
if (pMixerControl[i].dwControlType == dwControlType){
MIXERCONTROLDETAILS mixerControlDetails;
PMIXERCONTROLDETAILS_BOOLEAN pmxcd_lt;

pmxcd_lt = (PMIXERCONTROLDETAILS_BOOLEAN)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pMixerControl[i].cMultipleItems * sizeof(PMIXERCONTROLDETAILS_BOOLEAN));
mixerControlDetails.cbStruct = sizeof(mixerControlDetails);
mixerControlDetails.dwControlID = pMixerControl[i].dwControlID;
mixerControlDetails.cMultipleItems = pMixerControl[i].cMultipleItems;
mixerControlDetails.cChannels = 1;
mixerControlDetails.cbDetails = sizeof(*pmxcd_lt);
mixerControlDetails.paDetails = pmxcd_lt;

mmr = mixerGetControlDetails((HMIXEROBJ) m_hMixer, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE );
if (mmr != MMSYSERR_NOERROR){
HeapFree(GetProcessHeap(), 0, pmxcd_lt);
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}


if (bStatus == TRUE){
if (dwControlType == MIXERCONTROL_CONTROLTYPE_MUX){
for (j = 0; j < mixerControlDetails.cMultipleItems; j ){
pmxcd_lt[j].fValue = 0;
}
}
pmxcd_lt[index].fValue = 1;
}
else
pmxcd_lt[index].fValue = 0;
mmr = mixerSetControlDetails((HMIXEROBJ) m_hMixer, &mixerControlDetails, 0L);
HeapFree(GetProcessHeap(), 0, pmxcd_lt);
HeapFree(GetProcessHeap(), 0, pMixerControl);
if (mmr != MMSYSERR_NOERROR)
return TRUE;
else
return FALSE;
}
}
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}

BOOL CMixerControl::EnableAllDevice(DWORD dwDestinationType, BOOL bStatus)
{
DWORD dwControlType, dwControls;
MIXERLINE mxLine, mixerline;
UINT i, j;
BOOL bMixerList = FALSE;
MMRESULT mmr;
MIXERCONTROLDETAILS mixerControlDetails;
PMIXERCONTROLDETAILS_BOOLEAN pmxcd_lt;
MIXERLINECONTROLS mixerLineControls;
PMIXERCONTROL pMixerControl;

mxLine.cbStruct = sizeof(mxLine);
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType)
break;
}

if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_SINGLESELECT) == TRUE){
dwControlType = MIXERCONTROL_CONTROLTYPE_SINGLESELECT;
bMixerList = TRUE;
}
if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT) == TRUE){
dwControlType = MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT;
bMixerList = TRUE;
}
if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_MUX) == TRUE){
dwControlType = MIXERCONTROL_CONTROLTYPE_MUX;
bMixerList = TRUE;
}
if (CheckControlType(mxLine, MIXERCONTROL_CONTROLTYPE_MIXER) == TRUE){
dwControlType = MIXERCONTROL_CONTROLTYPE_MIXER;
bMixerList = TRUE;
}

dwControls = mxLine.cControls;
if (bMixerList == TRUE){
pMixerControl = (PMIXERCONTROL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MIXERCONTROL)*dwControls);
mixerLineControls.cbStruct = sizeof(mixerLineControls);
mixerLineControls.dwLineID = mxLine.dwLineID;
mixerLineControls.dwControlID = m_MxId;
mixerLineControls.cControls = mxLine.cControls;
mixerLineControls.cbmxctrl = sizeof(MIXERCONTROL);
mixerLineControls.pamxctrl = pMixerControl;
mmr = mixerGetLineControls((HMIXEROBJ) m_hMixer, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}
for (i = 0; i < dwControls; i ){
if (pMixerControl[i].dwControlType == dwControlType){
pmxcd_lt = (PMIXERCONTROLDETAILS_BOOLEAN)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, pMixerControl[i].cMultipleItems * sizeof(PMIXERCONTROLDETAILS_BOOLEAN));
mixerControlDetails.cbStruct = sizeof(mixerControlDetails);
mixerControlDetails.dwControlID = pMixerControl[i].dwControlID;
mixerControlDetails.cMultipleItems = pMixerControl[i].cMultipleItems;
mixerControlDetails.cChannels = 1;
mixerControlDetails.cbDetails = sizeof(*pmxcd_lt);
mixerControlDetails.paDetails = pmxcd_lt;

mmr = mixerGetControlDetails((HMIXEROBJ) m_hMixer, &mixerControlDetails, MIXER_GETCONTROLDETAILSF_VALUE );
if (mmr != MMSYSERR_NOERROR){
HeapFree(GetProcessHeap(), 0, pmxcd_lt);
HeapFree(GetProcessHeap(), 0, pMixerControl);
return FALSE;
}
for (j = 0; j < mixerControlDetails.cMultipleItems; j ){
if (bStatus == TRUE)
pmxcd_lt[j].fValue = 1;
else
pmxcd_lt[j].fValue = 0;
}
mmr = mixerSetControlDetails((HMIXEROBJ) m_hMixer, &mixerControlDetails, 0L);
HeapFree(GetProcessHeap(), 0, pmxcd_lt);
HeapFree(GetProcessHeap(), 0, pMixerControl);
if (mmr != MMSYSERR_NOERROR)
return TRUE;
else
return FALSE;
}
}
}
else{
if (bStatus == FALSE)
SetDetailValue(1, MIXERCONTROL_CONTROLTYPE_MUTE, mxLine);
else
SetDetailValue(0, MIXERCONTROL_CONTROLTYPE_MUTE, mxLine);
for (i = 0; i < mxLine.cConnections; i ){
mixerline.dwDestination = mxLine.dwDestination;
mixerline.cbStruct = sizeof(mixerline);
mixerline.dwSource = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mixerline, MIXER_GETLINEINFOF_SOURCE);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (bStatus == FALSE)
SetDetailValue(1, MIXERCONTROL_CONTROLTYPE_MUTE, mixerline);
else
SetDetailValue(0, MIXERCONTROL_CONTROLTYPE_MUTE, mixerline);
}
}
return FALSE;
}

BOOL CMixerControl::SetMixerValue(DWORD dwValue, DWORD dwControlType, DWORD dwSourceType, DWORD dwDestinationType)
{
MIXERLINE mxLine;
UINT i, j;
MMRESULT mmr;
DWORD dwConnections;

//Initial value
mxLine.cbStruct = sizeof(mxLine);
//Get Destnation Volume Range
if (dwSourceType == 0){
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
return SetDetailValue(dwValue, dwControlType, mxLine);
}
}
}
else{
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
dwConnections = mxLine.cConnections;
for (j = 0; j < dwConnections; j ){
mxLine.cbStruct = sizeof(mxLine);
mxLine.dwSource = j;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_SOURCE);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwSourceType){
return SetDetailValue(dwValue, dwControlType, mxLine);
}
}
}
}
}
return FALSE;
}

BOOL CMixerControl::GetComponentName(char *szComponentName, DWORD dwSourceType, DWORD dwDestinationType)
{
MIXERLINE mxLine;
UINT i, j;
MMRESULT mmr;
DWORD dwConnections;

//Initial value
mxLine.cbStruct = sizeof(mxLine);
if (dwSourceType == 0){
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
//Get mixer line info
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUF
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return NULL;
}
if (mxLine.dwComponentType == dwDestinationType){
wsprintf(szComponentName, "%s", mxLine.szName);
return TRUE;
}
}
}
else{
for (i = 0; i < m_Destinations; i ){
mxLine.dwDestination = i;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_DESTINATION);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwDestinationType){
dwConnections = mxLine.cConnections;
for (j = 0; j < dwConnections; j ){
mxLine.cbStruct = sizeof(mxLine);
mxLine.dwSource = j;
mmr = mixerGetLineInfo((HMIXEROBJ)m_hMixer, &mxLine, MIXER_GETLINEINFOF_SOURCE);
if (mmr != MMSYSERR_NOERROR){
#ifdef _DEBUG
sprintf(m_MessageBuffer, "mixerGetLineInfo() failed on mmr=%u!\nLine : %d\nFile : %s", mmr, __LINE__, __FILE__);
MessageBox(m_hWnd, m_MessageBuffer, "Detect Error", MB_OK|MB_ICONEXCLAMATION);
#endif
return FALSE;
}
if (mxLine.dwComponentType == dwSourceType){
wsprintf(szComponentName, "%s", mxLine.szName);
return TRUE;
}
}
}
}
}
return FALSE;
}

系統時間:2024-05-06 15:30:45
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!