Delphi Sound - 在多个声卡之间选择输出

时间:2017-11-13 11:00:14

标签: delphi audio media-player soundcard

我试图为程序添加功能,该程序可以选择从组合框中选择声卡,然后使用该声卡在TMediaPlayer上输出。这是我到目前为止的代码,但MediaPlayer继续在默认声卡上播放。

unit Select_SoundCard_Update;

interface

uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, 
   Forms,
    Dialogs, MMSystem, StdCtrls, MPlayer;

type
  TForm1 = class(TForm)
    MediaPlayer1: TMediaPlayer;
    ComboBox1: TComboBox;
    btn1: TButton;
    dlgOpen1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1CloseUp(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
   { Private declarations }
  public
   { Public declarations }
 end;

var
   Form1: TForm1;
   outcaps: TWaveOutCaps;
   parms: MCI_WAVE_SET_PARMS;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
 ShowMessage('Jy het '+IntToStr(waveOutGetNumDevs) + ' soundcard(s) wat 
 opgetel word.');
i := waveOutGetNumDevs;
for i := 0 to i - 1 do
   begin
      waveOutGetDevCaps(i, @outcaps, SizeOf(outcaps));
      Combobox1.Items.Add(outcaps.szPname);
   end;
   Combobox1.ItemIndex := 0;
end;

procedure TForm1.ComboBox1CloseUp(Sender: TObject);
begin
   MediaPlayer1.Close;
   parms.wOutput := Combobox1.itemindex;
   mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_WAVE_OUTPUT, 
   Longint(@parms));
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
   ShowMessage(IntToStr(MediaPlayer1.DeviceID));
  MediaPlayer1.Close;
if dlgOpen1.Execute then
   begin
     MediaPlayer1.FileName := dlgOpen1.FileName;
     MediaPlayer1.Open;
   end;
end;

end.

我做错了什么?请提出任何建议,我们已经好几天了。提前谢谢。

0 个答案:

没有答案