I'm trying to add functionality to a program that gives the option to select a sound card out of a combobox and then using that sound card for output on a TMediaPlayer. Here's the code I have so far but the MediaPlayer keeps on playing on the default sound card.
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.
What am I doing wrong? Please any advice would be appreciated have been at this for days now. Thanks in advance.