BASS.NET API for the Un4seen BASS Audio LibraryBroadCast ClassBASS.NET API for the Un4seen BASS Audio Library
Enables streaming of audio content to the internet.
Inheritance Hierarchy

SystemObject
  Un4seen.Bass.MiscBroadCast

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

public sealed class BroadCast

The BroadCast type exposes the following members.

Constructors

  NameDescription
Public methodBroadCast
Creates an instance of the broadcasting class using the specified streaming server.
Top
Properties

  NameDescription
Public propertyAutomaticMode
Gets if the automatic mode was used (, if AutoConnect was called, else meaning Connect was used instead).
Public propertyAutoReconnect
Gets or Sets if the broadcast connection should automatically be reconnected in case of a connection or encoder error (default=).
Public propertyIsConnected
Connected to the server? (=connected).
Public propertyIsStarted
Is the server started? (=started).
Public propertyNotificationSuppressDataSend
Gets or Sets, if the DataSend event will be raised when subscribed to the Notification event handler (default is ).
Public propertyNotificationSuppressIsAlive
Gets or Sets, if the IsAlive event will be raised when subscribed to the Notification event handler and AutoReconnect is enabled (default is ).
Public propertyReconnectTimeout
Gets or Sets the reconnect timeout in seconds (default is 5sec.).
Public propertyServer
Returns the streaming server interface which is used with this instance.
Public propertyStatus
Gets the current broadcast status.
Public propertyTotalBytesSend
Returns the total number of bytes send to the server during a broadcast.
Public propertyTotalConnectionTime
Returns the total online connection time (for how long the broadcast is already running since it was connected).
Top
Methods

  NameDescription
Public methodAutoConnect
Public methodCode exampleConnect
Public methodDisconnect
Public methodGetListeners
Returns the number of listeners currently connected.
Public methodGetStats
Returns the XML stats of the server.
Public methodSendData
Sends encoded sample data manually to the broadcast server (e.g. the data as received in an own ENCODEPROC).
Public methodCode exampleStartEncoder
Starts the underlying encoder (see Encoder).
Public methodStopEncoder
Stops the Encoder
Public methodUpdateTitle(String, String)
Updates the title of the playing song on a broadcast server.
Public methodUpdateTitle(TAG_INFO, String)
Updates the title of the playing song on a broadcast server.
Top
Events

  NameDescription
Public eventNotification
Event handler used to notify that the BroadCast status has changed or that a BroadCast event has occurred.
Top
Remarks

To setup broadcast streaming you first need to create an instance of a class, which is derived from the StreamingServer class (e.g. SHOUTcast or ICEcast). These classes will contain all necessary configuration data (e.g. server address an port, username and password, station description etc., as well as an IBaseEncoder instance, which defines the target broadcasting encoder format).

The BroadCast class support manual streaming (e.g. in your own DSPPROC or ENCODEPROC) as well as automatic streaming. Automatic streaming is implemented internally also via a user DSP.

If you want to broadcast to multiple outputs (multiple servers) you need to create an instance for each output seperately.

Examples

The following example uses the generic Encoder-Framework with the generic StreamingServer-Framework to implement streaming of any recording data (here uing LAME MP3 encoding to a SHOUTcast server):
VB
Private _recHandle As Integer
Private _broadCast As BroadCast
...
_recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, Nothing, 0)
...
' create an encoder instance (e.g. for MP3 use EncoderLAME):
Dim lame As New EncoderLAME(_recHandle)
lame.InputFile = Nothing 'STDIN
lame.OutputFile = Nothing 'STDOUT
lame.LAME_Bitrate = CInt(EncoderLAME.BITRATE.kbps_56)
lame.LAME_Mode = EncoderLAME.LAMEMode.Mono
lame.LAME_TargetSampleRate = CInt(EncoderLAME.SAMPLERATE.Hz_22050)
lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality

' create a StreamingServer instance (e.g. SHOUTcast) using the encoder:
Dim shoutcast As New SHOUTcast(lame)
shoutcast.ServerAddress = "localhost"
shoutcast.ServerPort = 8000
shoutcast.Password = "changeme"
shoutcast.PublicFlag = True

' use the BroadCast class to control streaming:
_broadCast = New BroadCast(shoutcast)
_broadCast.AutoReconnect = True
AddHandler _broadCast.Notification, AddressOf OnBroadCast_Notification
_broadCast.AutoConnect()

Private Sub OnBroadCast_Notification(sender As Object, e As BroadCastEventArgs)
  ' Note: this method might be called from another thread (non UI thread)!
  If _broadCast Is Nothing Then
    Return
  End If
  If _broadCast.IsConnected Then
    ' we are connected...
  Else
    ' we are not connected...
  End If 
End Sub
private int _recHandle;
private BroadCast _broadCast;
...
_recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, null, 0);
...
// create an encoder instance (e.g. for MP3 use EncoderLAME):
EncoderLAME lame = new EncoderLAME(_recHandle);
lame.InputFile = null;    //STDIN
lame.OutputFile = null;    //STDOUT
lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_56;
lame.LAME_Mode = EncoderLAME.LAMEMode.Mono;
lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_22050;
lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;

// create a StreamingServer instance (e.g. SHOUTcast) using the encoder:
SHOUTcast shoutcast = new SHOUTcast(lame);
shoutcast.ServerAddress = "localhost";
shoutcast.ServerPort = 8000;
shoutcast.Password = "changeme";
shoutcast.PublicFlag = true;

// use the BroadCast class to control streaming:
_broadCast = new BroadCast(shoutcast);
_broadCast.AutoReconnect = true;
_broadCast.Notification += new BroadCastEventHandler(OnBroadCast_Notification);
_broadCast.AutoConnect();

private void OnBroadCast_Notification(object sender, BroadCastEventArgs e)
{
  // Note: this method might be called from another thread (non UI thread)!
  if (_broadCast == null)
    return;
  if (_broadCast.IsConnected)
  {
    // we are connected...
  }
  else
  {
    // we are not connected...
  }
}
See Also

Reference