problem in play multi sound in inno setup

108 views Asked by At

Im use bass lib to play 2 sound in my installer

  1. background sound (play in all installer page except license page)
  2. a sound only play when user enter license page (background sound pause and new sound play)

im use some help to get license sound to work on this Question

everything work good (background sound play until user come to license page, in license page other sound start play, and when user go to next page background sound play again) except one problem, if user pause background music before inter license page somehow this time when user inter to license page background sound play again, in better word bass lib skip play license page sound

this is my code for bass in inno setup

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 = {#MusicVolume};
  EncodingFlag = BASS_UNICODE;

var
  SoundStream: HSTREAM;
  LicenseSoundStream: HSTREAM;

//

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_ChannelPause(handle: DWORD): Boolean;
    external 'BASS_ChannelPause@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';

//

procedure MusicButtonClick(Sender: TObject);
begin
  case BASS_ChannelIsActive(SoundStream) of
    BASS_ACTIVE_PLAYING:
    begin
      if BASS_Pause then
        MusicButton.Caption := ExpandConstant('{cm:MusicButtonCaptionSoundOn}');
    end;
    BASS_ACTIVE_PAUSED:
    begin
      if BASS_Start then
        MusicButton.Caption := ExpandConstant('{cm:MusicButtonCaptionSoundOff}');
    end;
  end;
end;

//

if BASS_Init(-1, 44100, 0, 0, 0) then
    begin
      BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, 2500);
      ExtractTemporaryFile('{#MusicFile}');
      ExtractTemporaryFile('license.mp3');
      SoundStream :=
        BASS_StreamCreateFile(
          False, ExpandConstant('{tmp}\{#MusicFile}'), 0, 0, 0, 0,
          BASS_UNICODE or BASS_SAMPLE_LOOP);
      LicenseSoundStream :=
        BASS_StreamCreateFile(
          False, ExpandConstant('{tmp}\license.mp3'), 0, 0, 0, 0, BASS_UNICODE);
      BASS_ChannelPlay(SoundStream, False);
    end;

{ if page changed to license page }

begin
    if CurPageID = wpLicense then
    begin
      AboutButton.Hide;
      WizardForm.DirEdit.Hide;
      WizardForm.DirBrowseButton.Hide;
      WizardForm.GroupEdit.Hide;
      WizardForm.GroupBrowseButton.Hide;
      WizardForm.PageNameLabel.Hide;
      WizardForm.PageDescriptionLabel.Hide;
      WizardForm.UserInfoNameLabel.Hide;
      WizardForm.UserInfoNameEdit.Hide;
      WizardForm.BackButton.Visible := False;
      MusicButton.Visible := False;
      if LicenseSoundStream <> 0 then
      begin
        if BASS_ChannelIsActive(SoundStream) then BASS_ChannelPause(SoundStream);
        BASS_ChannelPlay(LicenseSoundStream, True);
        BASS_Start;
      end;
    end
      else
    begin
      { On other pages, restore the standard music }
      if SoundStream <> 0 then
      begin
        BASS_ChannelPause(LicenseSoundStream);
        BASS_ChannelPlay(SoundStream, False);
        MusicButton.Visible := true;
      end;
    end;
  end;

how can i fix this? thanks

0

There are 0 answers