libZPlay documentation (Win32)
ZPlay.SetCallbackFunc Method

Set callback function.

public bool SetCallbackFunc(TCallbackFunc CallbackFunc, TCallbackMessage Messages, int UserData);
TCallbackFunc CallbackFunc 
Address to callback function. Set this value to 0 to disable callback mechanism. 
TCallbackMessage Messages 
Specify messages you need to receive with callback function. This parameter can be combination of multiple callback messages. 
int UserData 
User data. This value will be passed to CallbackFunc as parameter. 
Return Values 
All OK. 
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. 

// global holder for our callback function, need this to prevent garbage collector to destroy our callback function
private TCallbackFunc CallbackFunc;

// callback function
public int MyCallbackFunc(uint objptr, int user_data, TCallbackMessage msg, uint param1, uint param2)
  switch (msg)
     case TCallbackMessage.MsgStreamBufferDoneAsync:
       // read more data and push into stream
       byte[] stream_data = null;
       int small_chunk = 100000;
       stream_data = br.ReadBytes(small_chunk);
       if (stream_data.Length > 0)
          player.PushDataToStream(ref stream_data, System.Convert.ToUInt32(stream_data.Length));
          byte[] tempMemNewData1 = null;
          player.PushDataToStream(ref tempMemNewData1, 0);

  return 0;

// ...

// global variable, prevent garbage collector to destroy this function
CallbackFunc = new TCallbackFunc(MyCallbackFunc);

// set callback function
player.SetCallbackFunc(CallbackFunc, (TCallbackMessage) TCallbackMessage.MsgStreamBufferDoneAsync, 0);



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