FPC trunk r44876
Lazarus trunk r63184
Mojave 10.14.6
AVMIDIPlayer class demo - Works as expected until the midi file finishes playing and the completion handler is called.
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$linkframework AVFoundation}
{$modeswitch cblocks}
...
procedure play (completionHandler: tblock); message 'play:';
...
// Executed when the midi file finishes playing
procedure myCompletionHandler;
begin
MyMidiPlayer.Stop;
MyMidiPlayer.setCurrentPosition(0);
WriteLn('Completion handler called');
Form1.PauseButton.Enabled := False;
Form1.StopPlayButton.Enabled := False;
end;
MyMidiPlayer.play(@myCompletionHandler);
Running the application in a terminal from its application bundle directory to read the WriteLn output.
If I comment out the disabling of the buttons in the completion handler, then the WriteLn happens as soon as the midi file finishes playing. If I don't comment those lines, then nothing happens until I click in the TrackBar pointer at which point the buttons are disabled and then, a few seconds later, the WriteLn output appears.
I originally also had updates to various label captions in the completion handler but they were not being updated. Without any clicking, eventually the WriteLn would appear after between 18 and 25 seconds. Clicking on the form would clear the label captions (not write the new content though) and a few seconds later the WriteLn output would appear.