.net Library - StarDust.CasparCG.net

Hi Da_Elf,

Do you try the given sample provided on git hub ?

Stardust OSC Sample

Don’t forget to initiate a connection to AMCP to use OSC.

Wich type of project do you use on Visual Studio ? WinForm, WPF, Console ?

Im working with Unity. I got everything figured out. I just wanted to be able to connect to CasparCG and send a command to play a video. Nothing fancy. I got it figured out and even did a tutorial on how to set it all up.

Ok you want to use my lib in the Unity3D game engine ?

1 Like

it works nicely :slight_smile: im only using the connection and the crosscutting (as seen in the tutorial i did)
Im just using unity for its UI. Its way better than when i used Livecode. I want to try to make an app with unity for my android to have it control casparcg. that would be cool
All ive used for now is Connect() Disconnect() and Send() hehehehe. simple
oh… and isConnected() is soooooo much better in unity than how i used to have to do it in livecode

New version of nuget release. I removed support of .NET 4.6.1 since it’s not supported any more by Microsoft. I’ll update all project to support .netstandard2.0 and 2.1. Demo are now in .NET 7.
I also added a new nuget package to allow us using microsoft dependency injection in your new .NET project.

NuGet Gallery | StarDust.CasparCG.net.Microsoft.DependencyInjection 2023.2.2.1

Hello there, I am having trouble using this library in my Windows Forms app that is supposed to be a tool to use a sports scoreboard template easier. I’m kinda new to dependency injection so I hope someone can help me.

My Form1 class:

namespace NRL_Scoreboard_v3
{
    using Microsoft.Extensions.DependencyInjection;
    using StarDust.CasparCG.net.AmcpProtocol;
    using StarDust.CasparCG.net.Device;
    using StarDust.CasparCG.net.Microsoft.DependencyInjections;
    using System.Diagnostics;

    public partial class Form1 : Form
    {
        private static readonly ServiceCollection services = new();
        private static readonly ServiceProvider serviceProvider = services.BuildServiceProvider();
        private ICasparDevice? casparDevice;
        CGManager? cg;
       private string HomeTeam = "";
        private string AwayTeam = "";
        private bool TeamsLocked = false;
        private int HomePenalties = 0;
        private int AwayPenalties = 0;
        private int HomeScrums = 0;
        private int AwayScrums = 0;
        private int HomeDropouts = 0;
        private int AwayDropouts = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            IServiceCollection collection = services.AddCasparCG();
            casparDevice = serviceProvider.GetService<ICasparDevice>();
            if (casparDevice == null )
            {
                MessageBox.Show("Unable to get Caspar Device");
            }
            else
            {
                casparDevice.ConnectionStatusChanged += CasparDevice_ConnectionStatusChanged;
            }
        }
        // other methods for button clicks
  }
}

The casparDevice is always returning null on load. I feel like I’ve done something really basic wrong with the initialization here.

Hello,

Your serviceProvider is build before you define your serviceCollection.
The order is important.

ServiceCollection services = new();
IServiceCollection collection = services.AddCasparCG();
ServiceProvider serviceProvider = services.BuildServiceProvider();
ICasparDevice casparDevice = serviceProvider.GetRequired<ICasparDevice>();

You can follow this article c# - How to use dependency injection in WinForms - Stack Overflow

Thanks so much. I looked up tutorials on DI online and couldn’t find anything clear. That Stack Overflow answer you gave looks good though. Thanks again.

I have another question. I have the library loading my HTML template and it’s working great, but does the library support sending Template Data as JSON instead of XML? I can write my update function to work with XML but obviously, JSON would be easier to work with. I looked at all the overloads that the Visual Studio IntelliSense found, but it didn’t look like any of them had a JSON flag.

Do you try to serialize your data as Json and send it as a string.

string jsonString = JsonSerializer.Serialize(yourTemplateObject);
_casparServer.Channels[0].CG.Add(0,1,jsonString)

hi @rom1

I got this error when install package StarDust.CasparCG.net.Microsoft.DependencyInjection

|Error||Could not install package ‘StarDust.CasparCG.net.Microsoft.DependencyInjection 2023.2.2.1’. You are trying to install this package into a project that targets ‘.NETFramework,Version=v4.7.2’, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

any suggest?

Thanks

1 Like

Your version of DotNet framework is too old. Please update to .net 6.

in visual studio installer, I have runtime version 6.0 and 7.0

Runtime is to run compiled application. You need to install the framework version and you need to target the framework version in your csproj.

I already install .net 7, but still got same error

Can you copy paste the content of your csproj file ?

can you explain the different between Windows Form App (.NET Framework) and Windows Form App ?
because when I created project with .NET Framework and try install the package its always show error
but when I created project without .NET Framework and try install the package its totally fine?

now I created project without .NET Framework, just Windows Form App, and its work

Another question

I want to update key on template, then I use this code

channel.CG.Add(1, 1, "Match ID");
channel.CG.Update(1, 1, "<templateData><componentData id=\"matchday\"><data id=\"text\" value=\"TEAM A\"/></componentData><componentData id=\"groups\"><data id=\"text\" value=\"TEAM B\"/></componentData></templateData>");
channel.CG.Play(1, 1);

but data not changed
any suggest?

The CasparCGDataCollection class might be useful here. I think it’s under Stardust.CasparCG.net.Models, but not 100% sure.

Code example:

CasparCGDataCollection data = new() {
   {"matchday", "TEAM A"},
   {"groups", "TEAM B"}
};
channel.CG.Update(1, 1, data);

As an aside, I would also compare the result of the Update method to the AMCPError enum, where AMCPError.None indicates a successful update, but I’ll leave you to work that out if you wish.

works like charm, thanks @bradnak

Sorry if I ask a lot about casparcg, because previously I used the XPression API for broadcast purposes
I want to try something new, on the other hand casparcg is free software unlike XPression

:smiley: