libZPlay documentation (Win32)
IndexReferenceHome
PreviousUpNext
ZPlay.SetCallbackFunc Method

Set callback function.

Pascal
function SetCallbackFunc(CallbackFunc: TCallbackFunc; Messages: TCallbackMessage; UserData: Integer): Boolean;
Parameters 
Description 
CallbackFunc: TCallbackFunc 
Address to callback function. Set this value to 0 to disable callback mechanism. 
Messages: TCallbackMessage 
Specify messages you need to receive with callback function. This parameter can be combination of multiple callback messages. 
UserData: Integer 
User data. This value will be passed to CallbackFunc as parameter. 
Return Values 
Description 
True 
All OK. 
False 
Error. To get error message read here

All callback messages are sent from decoding thread. 

There are 2 types of callback messages, blocking (sync) and not blocking (async). 

Blocking message will block decoding thread until callback function returns. Non blocking mesage will not block decoding thread. 

Warning: callback function must have __stdcall calling convention. 

Note: You must protect CallbackFunc from garbage collector. Use global or static variable to keep alive callback function all the time. If you don't protect CallbackFunc, garbage collector will destroy or move this function and you will get memory access error when next callback event occurrs. 


// callback function

Function player_callback(objptr: Pointer; user_data: Integer; msg: TCallbackMessage; param1: Cardinal; param2: Cardinal):Integer;stdcall;
var
  ReadBytes: Integer;
beginResult := 0;
   case msg of
      libZPlay.MsgStreamNeedMoreDataAsync:
      begin
      // managed stream, read more data
        if FileHandle = 0 then
        begin
          player.PushDataToStream(nil, 0);
          Exit;
        end;

        if Buffer = nil then
        begin
          player.PushDataToStream(nil, 0);
          Exit;
        end;
        // read next data from file
        ReadBytes := FileRead(FileHandle, Buffer^, ChunkSize);
        if ReadBytes = 0 then
        begin
          player.PushDataToStream(nil, 0);
          Exit;
        end;
        // push new data to stream
        player.PushDataToStream(Buffer, ReadBytes);
      end;
   end;
Result := 0;
end;

// ...

if player.SetCallbackFunc(Addr(player_callback), TCallbackMessage(libZPlay.MsgStreamNeedMoreDataAsync) , 0) = false then
begin
  MessageBox(0, PAnsiChar(player.GetError()), 'Fatal error' ,0);
end;

 

 

Copyright (c) 2010. Zoran Cindori - All rights reserved.

Web: http://libzplay.sourceforge.net/

Email: zcindori@inet.hr