Namespace: Un4seen.Bass.AddOn.Enc
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
[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: BooleanIf successful, is returned, else is returned. Use BASS_ErrorGetCode to get the error code.
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 CODE | Description |
---|---|
BASS_ERROR_HANDLE | handle is not valid. |
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(); } }