0
0

Hi all,

Ive currently got working a jukebox written in delphi using FMod for mp3 playing.

While tidying up the code, I was trying to put the code that handles the playlist and plays the tracks into a Component to keep it simple and easy for me to expand on.

The trouble is, in order to find when a stream has finished, I use a Callback. This is fine if the callback is used in the main form code as the Callback procedure sits outside the Form class and can reference the form to take the appropriate action. When this sits in a component however, I don’t understand how I can get it to fire off an event.

Heres what I mean:

[code:tx92ra3x]
type
TPlaylist = class(TListview)
private
fOnSongChanged : TNotifyEvent;
...
published
property OnSongChanged: TNotifyEvent read fOnSongChanged write fOnSongChanged;
...
end;

function StreamCallback(Stream: PFSoundStream; Buff: Pointer; Len,
Param: Integer): ByteBool; cdecl;

implementation

...
function StreamCallback(Stream: PFSoundStream; Buff: Pointer; Len,
Param: Integer): ByteBool; cdecl;
begin
//if Assigned(fOnSongChanged) then fOnSongChanged(Self);
end;
[/code:tx92ra3x]

The dilemma is how to fire the fOnSongChanged event from outside the Component class.

Can anyone shed any light on this?

Cheers
Ben

  • You must to post comments
0
0

declare your callback function outside the class and then pass a pointer to your object to the callback function eg:
[code:3usdqbmm]
function onStreamEnd (Stream: PFSoundStream; Buff: Pointer; Length, Param: Integer): ByteBool;stdcall;
var Mediaplayer:TMediaPlayer;
begin
mediaplayer:=tmediaplayer(param);
mediaplayer.next;
result:=false;
end;

procedure Tmediaplayer.open;
begin
{open track etc...

..
..}
FSOUND_Stream_SetEndCallback(FModHandle,OnStreamEnd,integer(self));
end;[/code:3usdqbmm]

  • You must to post comments
0
0

Thank you – I shall give it a try on Monday when I can get back to my coding!

Cheers

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.