BASS.NET API for the Un4seen BASS Audio LibraryBroadCastConnect Method BASS.NET API for the Un4seen BASS Audio Library

Namespace: Un4seen.Bass.Misc
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.12.0
Syntax

public bool Connect()

Return Value

Type: Boolean
on success, else (see LastError or LastErrorMessage for details).
Remarks

The automatic reconnect settings (AutoReconnect and ReconnectTimeout) will also work with a manual connection. But, you must create and handle your own ENCODEPROC callback and call Start(ENCODEPROC, IntPtr, Boolean) manually!

If already connected, this method will first Disconnect from the Server, which might result in stopping the underlying BaseEncoder.

If the channel handle (as defined in the ChannelHandle) is already playing, it will be shortly paused during the setup and resumed when done.

Note: If you have set the AutoReconnect property to this call will automatically try to reconnect even if this method returns !

Examples

This example demonstrates manual broadcasting:
VB
Private _broadCast As BroadCast
Private _myEncProc As ENCODEPROC
...
' create your encoder (using a recording handle)
Dim lame As New EncoderLAME(_recHandle)

' create an streaming server instance
Dim shoutcast As New SHOUTcast(lame)

' create the broadcast instance
_broadCast = New BroadCast(shoutcast)
_broadCast.AutoReconnect = True
AddHandler _broadCast.Notification, AddressOf OnBroadCast_Notification

' create your encoder callback
_myEncProc = New ENCODEPROC(AddressOf MyEncodingCallback)
' start the encoder (paused)
_broadCast.StartEncoder(_myEncProc, IntPtr.Zero, True)
' now connect to start your broadcast
_broadCast.Connect()
' and really start the encoder
_broadCast.Server.Encoder.Pause(False)
...

' your broadcast encoder callback implementation
Private Sub MyEncodingCallback(handle As Integer, channel As Integer, 
                               buffer As IntPtr, length As Integer, user As IntPtr)
  ' here we receive the encoded data back (manual mode)
  If _broadCast.IsConnected Then
    _broadCast.SendData(buffer, length)
  End If
End Sub

Private Sub OnBroadCast_Notification(sender As Object, e As BroadCastEventArgs)
  If e.EventType = BroadCastEventType.EncoderRestartRequired Then
    _broadCast.StartEncoder(_myEncProc, 0)
  End If 

  If Not _broadCast.IsConnected Then
    ' connection lost
  End If
End Sub
private BroadCast _broadCast;
private ENCODEPROC _myEncProc;
...
// create your encoder (using a recording handle)
EncoderLAME lame = new EncoderLAME(_recHandle);

// create an streaming server instance
SHOUTcast shoutcast = new SHOUTcast(lame);

// create the broadcast instance
_broadCast = new BroadCast(shoutcast);
_broadCast.AutoReconnect = true;
_broadCast.Notification += new BroadCastEventHandler(OnBroadCast_Notification);

// create your encoder callback
_myEncProc = new ENCODEPROC(MyEncodingCallback);
// start the encoder (paused)
_broadCast.StartEncoder(_myEncProc, IntPtr.Zero, true);
// now connect to start your broadcast
_broadCast.Connect();
// and really start the encoder
_broadCast.Server.Encoder.Pause(false);
...

// your broadcast encoder callback implementation
private void MyEncodingCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
{
  // here we receive the encoded data back (manual mode)
  if ( _broadCast.IsConnected )
  {
    _broadCast.SendData(buffer, length);
  }
}

private void OnBroadCast_Notification(object sender, BroadCastEventArgs e)
{
  if (e.EventType == BroadCastEventType.EncoderRestartRequired)
    _broadCast.StartEncoder(_myEncProc, 0);

  if (!_broadCast.IsConnected)
  {
    // connection lost
  }
}
See Also

Reference