2016-11-07 59 views
1

Bass Audio Library on/off Button中的這段代碼是否「暫停」,如何將其更改爲「靜音」?如何使用Inno Setup中的BASS庫將音頻靜音(更改音量)

我應該改變什麼?

const 
    BASS_SAMPLE_LOOP = 4; 
    BASS_ACTIVE_STOPPED = 0; 
    BASS_ACTIVE_PLAYING = 1; 
    BASS_ACTIVE_STALLED = 2; 
    BASS_ACTIVE_PAUSED = 3; 
    BASS_UNICODE = $80000000; 
    BASS_CONFIG_GVOL_STREAM = 5; 
const 
    #ifndef UNICODE 
    EncodingFlag = 0; 
    #else 
    EncodingFlag = BASS_UNICODE; 
    #endif 
type 
    HSTREAM = DWORD; 

function BASS_Init(device: LongInt; freq, flags: DWORD; 
    win: HWND; clsid: Cardinal): BOOL; 
    external '[email protected]:bass.dll stdcall'; 
function BASS_StreamCreateFile(mem: BOOL; f: string; offset1: DWORD; 
    offset2: DWORD; length1: DWORD; length2: DWORD; flags: DWORD): HSTREAM; 
    external '[email protected]:bass.dll stdcall'; 
function BASS_Start: BOOL; 
    external '[email protected]:bass.dll stdcall'; 
function BASS_Pause: BOOL; 
    external '[email protected]:bass.dll stdcall'; 
function BASS_ChannelPlay(handle: DWORD; restart: BOOL): BOOL; 
    external '[email protected]:bass.dll stdcall'; 
function BASS_SetConfig(option: DWORD; value: DWORD): BOOL; 
    external '[email protected]:bass.dll stdcall'; 
function BASS_ChannelIsActive(handle: DWORD): DWORD; 
    external '[email protected]:bass.dll stdcall'; 
function BASS_Free: BOOL; 
    external '[email protected]:bass.dll stdcall'; 

var 
    SoundStream: HSTREAM; 
    SoundCtrlButton: TNewButton; 

procedure SoundCtrlButtonClick(Sender: TObject); 
begin 
    case BASS_ChannelIsActive(SoundStream) of 
    BASS_ACTIVE_PLAYING: 
    begin 
     if BASS_Pause then 
     SoundCtrlButton.Caption := 
      ExpandConstant('{cm:SoundCtrlButtonCaptionSoundOn}'); 
    end; 
    BASS_ACTIVE_PAUSED: 
    begin 
     if BASS_Start then 
     SoundCtrlButton.Caption := 
      ExpandConstant('{cm:SoundCtrlButtonCaptionSoundOff}'); 
    end; 
    end; 
end; 

procedure InitializeWizard; 
begin 
    ExtractTemporaryFile('tune.mp3'); 
    if BASS_Init(-1, 44100, 0, 0, 0) then 
    begin 
    SoundStream := BASS_StreamCreateFile(False, 
     ExpandConstant('{tmp}\tune.mp3'), 0, 0, 0, 0, 
     EncodingFlag or BASS_SAMPLE_LOOP); 
    BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 2500); 
    BASS_ChannelPlay(SoundStream, False); 

    SoundCtrlButton := TNewButton.Create(WizardForm); 
    SoundCtrlButton.Parent := WizardForm; 
    SoundCtrlButton.Left := 8; 
    SoundCtrlButton.Top := WizardForm.ClientHeight - 
     SoundCtrlButton.Height - 8; 
    SoundCtrlButton.Width := 40; 
    SoundCtrlButton.Caption := 
     ExpandConstant('{cm:SoundCtrlButtonCaptionSoundOff}'); 
    SoundCtrlButton.OnClick := @SoundCtrlButtonClick; 
    end; 
end; 

procedure DeinitializeSetup; 
begin 
    BASS_Free; 
end; 
+0

我不明白這個問題。你只是想改變*「暫停」*文本* *「靜音」*文本?或者你是否真的想要實現「靜音」功能,如將音量設置爲0%,而不是實際暫停媒體?但是這對於純音頻媒體(.mp3)沒有意義,對吧? - 無論如何,你的代碼適合我。 - 向我們展示你的'[Files]'部分。你使用了什麼'bass.dll'? –

+0

「靜音」功能,將音量設置爲0%,這有可能嗎?我使用[unseseen](http://www.un4seen.com/)'bass.dll' – DDoS

+0

請參閱我的答案。但首先,你需要編寫你已經有效的代碼。你有一些問題。但這是一個不同的話題。這個對我有用。 –

回答

1

爲了控制音量,則使用與BASS_SetConfigoption設置爲:

SoundCtrlButtonClick將取代您的問題中暫停/恢復執行相同命名的功能。

var 
    Muted: Boolean; 

procedure SoundCtrlButtonClick(Sender: TObject); 
begin 
    if not Muted then 
    begin 
    if BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 0) then 
    begin 
     SoundCtrlButton.Caption := 'unmute'; 
     Muted := True; 
    end; 
    end 
    else 
    begin 
    if BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 2500) then 
    begin 
     SoundCtrlButton.Caption := 'mute'; 
     Muted := False; 
    end; 
    end; 
end; 
+0

Ahm ..我很抱歉地說這個,但是我應該在哪裏插入我的代碼[script](https://drive.google.com/open?id=0BzPmkOR1ZhRfczU4c3BldWpxMHc)。請 – DDoS

+0

而不是'程序SoundCtrlButtonClick(Sender:TObject); ....結束;'塊。 –

+0

我意識到我的實現過於複雜。看到我編輯的答案。 –

相關問題