Skip to content
Christopher edited this page Nov 26, 2013 · 13 revisions

Welcome to the CasparCGNetConnector wiki!

This wiki will hold the development documentation for CasparCGNetConnector.

CasparCGNetConnector is a library for DOTNET projects connection CasparCG and your cilent.

Overview:

The library is a object oriented connector to the CasparCG Server using a ACMP2 to object mapping. The main objects are:

CasparCGConnection:
The CasparCGConnection will handle all the networking. It connects to a given server, monitors the connection status and is used when ever you want to communicate with the server. The complete library is designed to work with multiple connections. So you can easily reuse all objects like Commands, Media etc. for different server instances.

VB:

Dim WithEvents con as new CasparCGConnection("server.address", 5250)
addHandler(con.disconnected, AddressOf onDisconnect)
addHandler(con.connected, AddressOf onConnect)
con.connect()

C#:

CasparCGConnection con = new CasparCGConnection("server.address", 5250);
con.connected += new CasparCGConnection.connectedEventHandler(onConnect);
con.disconnected += new CasparCGConnection.disconnectedEventHandler(onDisconnect);
con.connect();

CasparCGResponse:
In order to have a duplex communication, each command send via a CasparCGConnection will return a CasparCGResponse. It will hold status information and a possible answer given by the server. Use it to verify everything went as you wished and to get access to the server response.
VB:

Dim response as CasparCGResponse
response = con.sendCommand("play 1-1 amb")
if response.isOK() then
  Console.WriteLine("Responded Data: " + response.getData())
  Console.WriteLine("Responded XML Data: " + response.getXMLData())
else if response.isERR() then
  Console.WriteLine("Error executing command " + response.getComnmand() + ": " + response.getServerMessage())
end if

C#:

CasparCGResponse response = con.sendCommand("play 1-1 amb");
if (response.isOK()) {
  Console.WriteLine("Responded Data: " + response.getData());
  Console.WriteLine("Responded XML Data: " + response.getXMLData());
} else if (response.isERR()) {
  Console.WriteLine("Error executing command " + response.getComnmand() + ": " + response.getServerMessage());
}

CasparCGCommand:
The library holds a bundle of predefined ACMP commands mapped to AbstractCasparCGCommand objects. These are more than just a simple mapping. They offer some more functions. like version control, descriptions for the command and it's parameters etc. There is more than one way to use them. The easiest is to define a well known instance of the command you need by calling it's constructor with the parameters needed and execute it. But you can set the parameters of the command later if you like, too.
VB:

Dim cmd as New PlayCommand(1, 1, "amb", True)
If cmd.execute(con).isOK then
  Console.WriteLine("Yeah, it's playing!")
Else
  Console.WriteLine("Oh no, something went wrong. Let's check the the server message: " + cmd.getResponse.getServerMessage())
End If

C#:

PlayCommand cmd = New PlayCommand(1, 1, "amb", True);
if (cmd.execute(con).isOK) {
  Console.WriteLine("Yeah, it's playing!");
} else {
  Console.WriteLine("Oh no, something went wrong. Let's check the the server message: " + cmd.getResponse.getServerMessage());
}

The other way is for generic UI use. You can explore all supported commands at runtime with the CasparCGCommandFactory. This is a powerful feature for a client as you get a list of commands, a description for them and their parameters. Along with the version control, you can offer only those commands to your user, which are supported by the connected server. The example for this case is more complex. Please see the example project for the code (VB only).

CasparCGMedia:
All items which are playable by the CasparCG Server will be mapped to CasparCGMedia classes and objects. These objects will hold metadata for the media and offers some related functions like retrieving the thumbnail of a clip or setting fields of a template. So, when dealing with clips, templates etc. you can manipulate objects instead of sending strings. All commands related to media will accept these objects as parameters.
VB:

Dim media as new CasparCGMovie("amb")
media.fillMediaInfo(con)
Console.WriteLine("All media infos we got from the server:")
For Each info As String In media.getInfos.Keys
  Console.WriteLine(vbTab & info & ": " & media.getInfo(info))
Next

media.fillThumbnail(con)
showBase64Image(media.getBase64Thumb())

Dim cmd as new PlayCommand(media)
cmd.execute(con)

C#:

CasparCGMovie media = new CasparCGMovie("amb");
media.fillMediaInfo(con);
Console.WriteLine("All media infos we got from the server:");
foreach String info in media.getInfos.Keys {
  Console.WriteLine("\t" & info & ": " & media.getInfo(info));
}

media.fillThumbnail(con);
showBase64Image(media.getBase64Thumb());

PlayCommand cmd = new PlayCommand(media);
cmd.execute(con);
Clone this wiki locally