.net Library - StarDust.CasparCG.net

This is a lot off effort to get thumbnails, It would be nice to let the scanner automatic created thumnails in a certain directory, like CaparCG did in 2.1 and earlier…

Thanks for this links rom1!

1 Like

Hi everyone. I need some help. I’m a newbie in C#…
Im building application with stardust liberty…my problem is that i cant get OSC to work. I try on demo project too, but i dont get any messages. I have OSC enabled on Caspar server. Can someone please point me in the right direction…
I put this in my code:

using StarDust.CasparCG.net.Connection;
using StarDust.CasparCG.net.AmcpProtocol;
using StarDust.CasparCG.net.OSC;
using Unity;

    static IUnityContainer _container;
    private static readonly bool quit;

    static void ConfigureIOC()
    {
        _container = new UnityContainer();

        _container.RegisterInstance<IServerConnection>(new StarDust.CasparCG.net.Connection.ServerConnection(new CasparCGConnectionSettings("192.168.1.38")));
        _container.RegisterType<IAMCPTcpParser, AmcpTCPParser>();
        _container.RegisterType<IOscListener, OscListener>();

    }

    private static async void OscStart()
    {
        var oscListener = _container.Resolve<IOscListener>();
        //oscListener.RegisterMethod("/channel/1/stage/layer/1/file/time");
        oscListener.AddToAddressBlackList("/channel/[0-9]/output/consume_time");
        oscListener.AddToAddressBlackList("/channel/1/stage/layer/1/profiler/time");

        oscListener.OscMessageReceived += OscListener_OscMessageReceived;
        oscListener.StartListening("192.168.1.38", 6250);
        //Console.WriteLine("Osc listener strarted");
        System.Diagnostics.Debug.WriteLine("Osc listener strarted");
    }

    private static void OscListener_OscMessageReceived(object sender, OscMessageEventArgs e)
    {
        //Console.WriteLine($"Osc message received: {e.OscPacket.ToString()}");
        System.Diagnostics.Debug.WriteLine($"Osc message received: {e.OscPacket.ToString()}");
    }

Thank you

I’ve been looking through tutorias on how to code something in c# to send messages to casparCG because i want to use Unity to make the client. I code in unity in c# but dont know how to get something like your project imported into my unity c# solution. Do you know how to do something like that?

Never mind. not sure is the using Unity is for unity the game engine or something else. Figured out how to use it for my needs

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 ?