BASS.NET API for the Un4seen BASS Audio Library

BassEncBASS_Encode_SetNotify Method

BASS.NET API for the Un4seen BASS Audio Library
Sets a callback function on an encoder (or all encoders on a channel) to receive notifications about its status.

Namespace:  Un4seen.Bass.AddOn.Enc
Assembly:  Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
Syntax

[DllImportAttribute("bassenc")]
public static bool BASS_Encode_SetNotify(
	int handle,
	ENCODENOTIFYPROC proc,
	IntPtr user
)

Parameters

handle
Type: SystemInt32
The encoder or channel handle... a HENCODE, HSTREAM, HMUSIC, or HRECORD.
proc
Type: Un4seen.Bass.AddOn.EncENCODENOTIFYPROC
Callback function to receive the notifications... = no callback.
user
Type: SystemIntPtr
User instance data to pass to the callback function.

Return Value

Type: Boolean
If successful, is returned, else is returned. Use BASS_ErrorGetCode to get the error code.
Remarks

When setting a notification callback on a channel, it only applies to the encoders that are currently set on the channel. Subsequent encoders will not automatically have the notification callback set on them, this function will have to be called again to set them up.

An encoder can only have one notification callback set. Subsequent calls of this function can be used to change the callback function, or disable notifications (proc = ).

The status of an encoder and its cast connection (if it has one) is checked when data is sent to the encoder or server, and by BASS_Encode_IsActive(Int32). That means an encoder's death will not be detected automatically, and so no notification given, while no data is being encoded.

If the encoder is already dead when setting up a notification callback, the callback will be triggered immediately.

ERROR CODEDescription
BASS_ERROR_HANDLEhandle is not valid.

Examples

Using the callback with a recording caster:
private ENCODENOTIFYPROC _myEndoderNotify;
private int _encoder = 0;
private int _recChan = 0;
private bool _autoreconnect = true;
...
_recChan = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, null, IntPtr.Zero);
Start();
...
private void Start()
{
  // start an encoder
  _encoder = BassEnc.BASS_Encode_Start(_recChan, "lame -r -x -s 44100 -b 128 -", 
                     BASSEncode.BASS_ENCODE_NOHEAD, null, IntPtr.Zero);
  _myEndoderNotify = new ENCODENOTIFYPROC(EncoderNotify);
  // start a caster
  BassEnc.BASS_Encode_CastInit(_encoder, "server.com:8000", "password", 
          BassEnc.BASS_ENCODE_TYPE_MP3, "name", "url", "genre", null, null, 128, true);
  // notify on dead encoder/connection 
  BassEnc.BASS_Encode_SetNotify(_encoder, _myEndoderNotify, IntPtr.Zero);
}

private void Stop()
{
  if (_encoder != 0)
  {
    BassEnc.BASS_Encode_SetNotify(_encoder, null, IntPtr.Zero);
    BassEnc.BASS_Encode_Stop(_encoder);
    _encoder = 0;
  }
}

private void EncoderNotify(int handle, int status, IntPtr user)
{
  // encoder/connection lost
  Stop();
  if (_autoreconnect)
  {
    // do auto-reconnect...
    Thread.Sleep(1000); // wait a sec
    Start();
  } 
}
See Also

Reference