.xm和.s3m文件无法从Inno Setup的BASS库中播放,只有.mp3 [英] .xm and .s3m file doesn't play in BASS library from Inno Setup, only .mp3
问题描述
当我选择.mp3文件时,它将在启动setup.exe时播放,但是当我将其更改为.xm或.s3m时,它将无法播放
When I choose .mp3 file, it will play when launching setup.exe but when I change it to .xm or .s3m, it doesn't play
[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 'BASS_Init@files:bass.dll stdcall';
function BASS_StreamCreateFile(mem: BOOL; f: string; offset1: DWORD;
offset2: DWORD; length1: DWORD; length2: DWORD; flags: DWORD): HSTREAM;
external 'BASS_StreamCreateFile@files:bass.dll stdcall';
function BASS_Start: BOOL;
external 'BASS_Start@files:bass.dll stdcall';
function BASS_Pause: BOOL;
external 'BASS_Pause@files:bass.dll stdcall';
function BASS_ChannelPlay(handle: DWORD; restart: BOOL): BOOL;
external 'BASS_ChannelPlay@files:bass.dll stdcall';
function BASS_SetConfig(option: DWORD; value: DWORD ): BOOL;
external 'BASS_SetConfig@files:bass.dll stdcall';
function BASS_ChannelIsActive(handle: DWORD): DWORD;
external 'BASS_ChannelIsActive@files:bass.dll stdcall';
function BASS_Free: BOOL;
external 'BASS_Free@files: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的文件.
What should I do? I want to use to original file which is .xm or .s3m and not the converted one which is .mp3.
如 Un4seen 所示,bass.dll支持.xm和.s3m.
As seen on Un4seen, bass.dll supports .xm and .s3m.
推荐答案
实际上,BASS_StreamCreateFile
对于两个文件都返回0.
Indeed, the BASS_StreamCreateFile
returns 0 for both files.
然后如果您调用 BASS_ErrorGetCode
,它将返回41 = BASS_ERROR_FILEFORM
(不受支持的文件格式).
And if you call BASS_ErrorGetCode
afterwards, it returns 41 = BASS_ERROR_FILEFORM
(unsupported file format).
function BASS_ErrorGetCode(): Integer;
external 'BASS_ErrorGetCode@files: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格式.
But as you correctly hinted, you should use the BASS_MusicLoad
for MO3 / IT / XM / S3M / MTM / MOD / UMX formats.
type
HMUSIC = DWORD;
function BASS_MusicLoad(
mem: BOOL; f: string; offset: Int64; length, flags, freq: DWORD): HMUSIC;
external 'BASS_MusicLoad@files:bass.dll stdcall';
将BASS_StreamCreateFile
调用替换为:
BASS_MusicLoad(
False, ExpandConstant('{tmp}\tune.xm'), 0, 0,
EncodingFlag or BASS_SAMPLE_LOOP, 0)
在语义上,您还应该将SoundStream
变量重命名为Music
或类似名称;并将其类型更改为HMUSIC
.
Semantically, your should also rename the SoundStream
variable to Music
or similar; and change its type to HMUSIC
.
这篇关于.xm和.s3m文件无法从Inno Setup的BASS库中播放,只有.mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!