2016-11-07 54 views
1

当我选择.mp3文件时,它将在启动setup.exe时播放,但当我将其更改为.xm或.s3m时,它不玩.xm和.s3m文件不会在Inno Setup的BASS库中播放,只有.mp3

[Setup] 
AppName=Bass Audio Project 
AppVersion=1.0 
DefaultDirName={pf}\Bass Audio Project 

[Files] 
Source: "Bass.dll"; Flags: dontcopy 
Source: "tune.xm"; Flags: dontcopy 

[CustomMessages] 
SoundCtrlButtonCaptionSoundOn=Play 
SoundCtrlButtonCaptionSoundOff=Mute 

[Code] 
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; 
    Muted: Boolean; 

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

procedure InitializeWizard; 
begin 
    ExtractTemporaryFile('tune.xm'); 
    if BASS_Init(-1, 44100, 0, 0, 0) then 
    begin 
    SoundStream := BASS_StreamCreateFile(False, 
     ExpandConstant('{tmp}\tune.xm'), 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; 

我该怎么办?我想使用原始文件,它是.xm或.s3m,而不是转换后的.mp3文件。

Un4seen所示,bass.dll支持.xm和.s3m。

+0

你可以请[XMPlay](http://support.xmplay.com/)中的文件吗? –

+0

你的意思是**播放**文件? [截图](http://i.imgur.com/1Z3LoXW.png) – DDoS

+0

你能和我们分享这个文件吗? –

回答

2

实际上,两个文件的BASS_StreamCreateFile都返回0。

如果之后致电BASS_ErrorGetCode,则返回41 = BASS_ERROR_FILEFORM(不受支持的文件格式)。

function BASS_ErrorGetCode(): Integer; 
    external '[email protected]:bass.dll stdcall'; 
SoundStream := BASS_StreamCreateFile(...); 
if SoundStream = 0 then 
begin 
    Log(Format('Error playing file, error code = %d', [BASS_ErrorGetCode])); 
end; 

但是当你正确时暗示,你应该使用BASS_MusicLoad为MO3/IT/XM/S3M/MTM/MOD/UMX格式。

type 
    HMUSIC = DWORD; 

function BASS_MusicLoad(
    mem: BOOL; f: string; offset: Int64; length, flags, freq: DWORD): HMUSIC; 
    external '[email protected]:bass.dll stdcall'; 

更换BASS_StreamCreateFile呼叫搭配:

BASS_MusicLoad(
    False, ExpandConstant('{tmp}\tune.xm'), 0, 0, 
    EncodingFlag or BASS_SAMPLE_LOOP, 0) 

语义,你也应该重新命名SoundStream变量Music或相似的;并将其类型更改为HMUSIC

+0

所以只有。 mp3文件可用。谢谢! – DDoS

+0

BASS库应该支持这些格式。但是这些特定的文件中可能会有一些特定的编解码器,标志或其他内容,这些不受库支持。 –

+0

'BASS_MusicLoad'而不是'BASS_StreamCreateFile'如何? – DDoS