Search code examples
delphibass

How do you play a list of files with bass.dll (libbass.dylib) in a Delphi FMX application?


I have a list of sound files stored in rows of a StringGrid that I want to play in sequence. That is, when one ends, the next line of the grid is read and that file played.

Bass has a BASS_SYNC_END event that allows for a callback procedure that I used successfully in the VCL version of my application. However, it does not in FMX.

The setup for the callback is this:

BASS_ChannelSetSync(chan1, BASS_SYNC_END, 0, @EndNormal, nil);

Which, at the end of playing the file, goes to:

procedure EndNormal(handle: HSYNC; channel, data: DWORD; user: DWORD); cdecl;
begin
  CPUnit1.NormPlaying := false;
  Form1.AdvTimer.Enabled := true;  // worked in VCL, ontimer proc gets file and plays
end;

In FMX, the variable will get changed, but the timer is not enabled since, I believe, it is part of the main GUI thread and not the BASS thread. Probably just lucky it worked in VCL, but that's history.

So, what is the technique to get the next file to play after one finishes?


Solution

  • Try to synchronize it:

    procedure EndNormal(handle: HSYNC; channel, data: DWORD;  user: DWORD); cdecl;
    begin
      TThread.Synchronize(NIL, // or Queue
        procedure
        begin
          CPUnit1.NormPlaying := false;
          Form1.AdvTimer.Enabled := true;
        end);
    end;