WinAPI: sndPlaySound - 播放 wav 檔案 WinAPI: sndPlaySound - 播放 wav 檔案
阿新 • • 發佈:2018-11-09
WinAPI: sndPlaySound - 播放 wav 檔案
//宣告: sndPlaySound( lpszSoundName: PChar; {聲音檔案} uFlags: UINT{播放選項} ): BOOL; //uFlags 引數可選值: SND_SYNC = 0; {同步播放, 程式須等到播放完畢才向下執行} SND_ASYNC = 1; {非同步播放, 在函式返回之後開始播放, 不影響程式繼續執行} SND_NODEFAULT = 2; {聲音檔案缺失時, 函式自動返回不播放預設聲音}SND_MEMORY = 4; {播放記憶體中的聲音, 譬如資原始檔中的聲音} SND_LOOP = 8; {迴圈播放, 需要和 SND_ASYNC 組合使用} SND_NOSTOP = 16;{如果當前正在播放聲音, 立即返回 False}
//舉例: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; typeTForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses MMSystem; {sndPlaySound 宣告在該單元} const s = 'C:\WINDOWS\Media\Windows XP 啟動.wav'; //同步播放 procedure TForm1.Button1Click(Sender: TObject); begin sndPlaySound(s, SND_SYNC); Beep; {播放完畢才會執行這句} end; //非同步播放 procedure TForm1.Button2Click(Sender: TObject); begin sndPlaySound(s, SND_ASYNC); Beep; {馬上會執行這句} end; //反覆播放 procedure TForm1.Button3Click(Sender: TObject); begin sndPlaySound(s, SND_LOOP or SND_ASYNC); end; end.
//sndPlaySound 也可以用來播放資源或記憶體中的聲音檔案, 參加示例:
http://www.cnblogs.com/del/archive/2008/02/15/1069523.html
//宣告: sndPlaySound( lpszSoundName: PChar; {聲音檔案} uFlags: UINT{播放選項} ): BOOL; //uFlags 引數可選值: SND_SYNC = 0; {同步播放, 程式須等到播放完畢才向下執行} SND_ASYNC = 1; {非同步播放, 在函式返回之後開始播放, 不影響程式繼續執行} SND_NODEFAULT = 2; {聲音檔案缺失時, 函式自動返回不播放預設聲音} SND_MEMORY = 4; {播放記憶體中的聲音, 譬如資原始檔中的聲音} SND_LOOP = 8; {迴圈播放, 需要和 SND_ASYNC 組合使用} SND_NOSTOP = 16;{如果當前正在播放聲音, 立即返回 False}
//舉例: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses MMSystem; {sndPlaySound 宣告在該單元} const s = 'C:\WINDOWS\Media\Windows XP 啟動.wav'; //同步播放 procedure TForm1.Button1Click(Sender: TObject); begin sndPlaySound(s, SND_SYNC); Beep; {播放完畢才會執行這句} end; //非同步播放 procedure TForm1.Button2Click(Sender: TObject); begin sndPlaySound(s, SND_ASYNC); Beep; {馬上會執行這句} end; //反覆播放 procedure TForm1.Button3Click(Sender: TObject); begin sndPlaySound(s, SND_LOOP or SND_ASYNC); end; end.
//sndPlaySound 也可以用來播放資源或記憶體中的聲音檔案, 參加示例:
http://www.cnblogs.com/del/archive/2008/02/15/1069523.html