我还需要能够控制它的音量。另外,如何控制系统声音的音量,以检测低音量或静音状态?
使用Shoban的链接来了解如何播放声音。
以下是控制设备音量的方法:
uses MMSystem;
type
TVolumeRec = record
case Integer of
0: (LongVolume: Longint) ;
1: (LeftVolume, RightVolume : Word) ;
end;
const DeviceIndex=5
{0:Wave
1:MIDI
2:CDAudio
3:Line-In
4:Microphone
5:Master
6:PC-loudspeaker}
procedure SetVolume(aVolume:Byte) ;
var
Vol: TVolumeRec;
begin
Vol.LeftVolume := aVolume shl 8;
Vol.RightVolume:= Vol.LeftVolume;
auxSetVolume(UINT(DeviceIndex), Vol.LongVolume) ;
end;
function GetVolume:Cardinal;
var
Vol: TVolumeRec;
begin
AuxGetVolume(UINT(DeviceIndex),@Vol.LongVolume) ;
Result:=(Vol.LeftVolume + Vol.RightVolume) shr 9;
end;
只需使用MM API(MSDN和Google上有大量示例)
char *mp3FilePath = ... ;
char *workingDirPath = ... ;
ShellExecute(hwnd, "open", mp3FilePath, NULL, workingDirPath, SW_SHOWNORMAL);