Broccoli Products home | contact us | about us
(by Lou Burne, last updated 10-APRIL-2012)
Development Notes
Creating Your Own RTMP Messages
For the messages that the RtmpClient does not support you can create your own using the message classes derived from RtmpMessage.

There are two ways to create your own RTMP messages.

Create an instance of the whichever message class correspondents to a message type, for example, a Command(AMF0) message could be created using the RtmpMessage_CommandAmf0 class.

Or create a raw message, and format the binary content yourself, which is a lot harder.

The following is an example of creating a "play" command message, starting with a new RtmpMessage_CommandAmf0 object.

The ComandAmf0 class has a property "Parameters", which is a reference to a list of parameters. The "Amf0" refers to the formatting of the parameters of the message.

// create a message object
RtmpMessage_CommandAmf0 cmd = new RtmpMessage_CommandAmf0(
     m_rtmpConnection.GetNextAmfStreamId(),
     m_rtmpConnection.Timestamp,
     1 // target is stream-id 1
);

// add parameter - string command for playing a stream
cmd.Parameters.Add( new RtmpParameter_String(null,"play") );

// add parameter - transaction id (must be 0)
cmd.Parameters.Add( new RtmpParameter_Number(null,0) );

// add parameter -- command object, can be null
cmd.Parameters.Add( new RtmpParameter_Null(null) );

// add parameter -- stream name
cmd.Parameters.Add( new RtmpParameter_String(null,"mp3:song01.mp3") );

// add parameter - start position (ms)
cmd.Parameters.Add( new RtmpParameter_Number(null,0) );

// add parameter - duration (-1 for all of it)
cmd.Parameters.Add( new RtmpParameter_Number(null,-1) );

// add parameter - reset (do not define true or false)
cmd.Parameters.Add( new RtmpParameter_Undefined(null) );

To send this message, pass the message to the connection's SendMessage function.
Customizing How You Connect
Some users will want to customize their connection message by adding additional parameters.

To do this, first create a vanilla connection message, using the function:
 
RtmpMessage_CommandAmf0 RtmpMessage_CommandAmf0.Build_NetConnection_Connect( ... );

This function takes the same parameters as the alternative ConnectToApplication function, and returns a valid Amf0 connection message.

Next, customize this message with your own parameters.  Below is an example of how to do this.  Here, I search for the OBJECT parameter in the Amf0 message, and add my own parameters to this.  If I had added the parameter to the message itself, it is unlikely the RTMP server that receives it would see it as a connection message.

// Find the OBJECTs
RtmpParameter[] paramList = connectionMsg.Parameters.FindByType(
     RtmpParameter.eAmfDataType.Object
);

// Add a STRING parameter to the first OBJECT
RtmpParameter_Object obParam = paramList[0] as RtmpParameter_Object;
obParam.Parameters.Add(
     new RtmpParameter_String("ExtraParamLabel","ParamValue")
);


Finally, I call the ConnectToApplication function with my customized message as the only parameter.

rtmpConn.ConnectToApplication(connectionMsg);

This code is included in the FileDump project code, FileDump.cs.
Contact form 
Use the contact form to send comments and requests for information to Broccoli Products.
Topic:
Message:
Email:
Broccoli Products Ltd © 1998-2012 Broccoli Products Ltd
Reg Number: 2895355
Reg Office: 27 Old Gloucester Street, London. WC1N 3AX
Privacy Policy
Copyright Notice
Liability Disclaimer
Contact Us