用TMediaPlayer.DeviceID获取设备号,通过此设备号利用MCI就能进行很多控制了,你要的切换声道代码如下
//设置播放时的模式,0立体声,1右声道,2左声道
function TF_Video.SetPlayMode(mode: integer):boolean;
var
s: MCI_DGV_SETAUDIO_PARMS ;
s1: MCI_SET_PARMS ;
err:integer;
begin
result:=False;
if Vod_Player.DeviceID>0 then
begin
//先关闭声音
err:=mciSendCommand(Vod_Player.DeviceID,MCI_SETAUDIO, MCI_SET_OFF ,0);
if (err<>0) then
begin
mciGetErrorString(err,buf,sizeof(buf) );
ShowMessage('SetPlayMode'+buf);
end;
if(err<>0)then
exit;
if mode=0 then
begin
s1.dwAudio:=MCI_SET_AUDIO_ALL;
s.dwValue:=MCI_DGV_SETAUDIO_SOURCE_STEREO;
//立体声道源
end;
if mode=1 then
begin
s1.dwAudio:=MCI_SET_AUDIO_LEFT;
s.dwValue:=MCI_DGV_SETAUDIO_SOURCE_LEFT;
//左声道源
end;
if mode=2 then
begin
s1.dwAudio:=MCI_SET_AUDIO_RIGHT;
s.dwValue:=MCI_DGV_SETAUDIO_SOURCE_RIGHT;
//右声道源
end;
if v_CurrentType='dat' then
begin
s.dwItem:=MCI_DGV_SETAUDIO_SOURCE;
//设置声道共享
err:=mciSendCommand(Vod_Player.DeviceID,MCI_SETAUDIO,MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SETAUDIO_ITEM ,integer(@s));
if (err<>0) then
begin
mciGetErrorString(err,buf,sizeof(buf) );
ShowMessage('SetPlayMode'+buf);
end;
//再打开声音
err:=mciSendCommand(Vod_Player.DeviceID,MCI_SETAUDIO, MCI_SET_ON ,0);
if (err<>0) then
begin
mciGetErrorString(err,buf,sizeof(buf) );
ShowMessage('SetPlayMode'+buf);
end;
end;
if v_CurrentType='wmv' then
begin
if mode=0 then
err:=mciSendCommand(Vod_Player.DeviceID,MCI_SETAUDIO,MCI_DGV_SETAUDIO_VALUE or MCI_DGV_SETAUDIO_ITEM ,integer(@s));
err:=mciSendCommand(Vod_Player.DeviceID,MCI_SET,MCI_SET_AUDIO or MCI_SET_ON ,integer(@s1));
end;
if (err<>0) then
begin
mciGetErrorString(err,buf,sizeof(buf) );
ShowMessage('SetPlayMode'+buf);
end;
v_PlayMode:=mode;
result:=True;
end;
end;