DELPHIでWAVとMP 3を再生
ある企業の知識コンテストに用いられ、より現場感を高めるために、音響効果を加えなければならない.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MPlayer, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
MediaPlayer1: TMediaPlayer;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses mmsystem;
// wav
procedure TForm1.Button1Click(Sender: TObject);
var
wavfile : String;
begin
wavfile := ' .wav';
sndplaysound(pchar(wavfile),snd_sync);
beep;
end;
// wav
procedure TForm1.Button2Click(Sender: TObject);
var
wavfile : String;
begin
wavfile := ' .wav';
sndplaysound(pchar(wavfile),SND_ASYNC or SND_LOOP);
beep;
end;
// MP3
procedure TForm1.Button3Click(Sender: TObject);
begin
MediaPlayer1.FileName := ' .mp3';
MediaPlayer1.Open;
MediaPlayer1.Play;
end;
end.