This is a .NET wrapper for the Snapcast RPC API.
- netstandard2.0
- net6.0
Install-Package justr.snapcast-api
Default
var api = new SnapcastApiClient("snapserver.lan", 1780);
With logging
// init logging
var loggerFactory = LoggerFactory.Create(_ => _.AddDebug());
var logger = loggerFactory.CreateLogger<SnapcastApiClient>();
// init api client
var api = new SnapcastApiClient(new() { Host = "snapserver.lan", Port = 1780 }, logger);
With di and logging
// init di
var serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
var serviceProvider = serviceCollection.BuildServiceProvider();
// init api client
var api = serviceProvider.GetService<SnapcastApiClient>();
static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(_ => _.AddDebug());
services.AddTransient<SnapcastApiClient>();
services.AddSingleton(new Connection { Host = "snapserver.lan", Port = 1780 });
}
Server
api.ServerGetStatus();
api.ServerGetRPCVersion();
api.ServerDeleteClient(clientId);
Client
api.ClientGetStatus(clientId);
api.ClientSetLatency(clientId, latency);
api.ClientSetName(clientId, name);
api.ClientSetMuted(clientId, muted);
api.ClientSetVolume(clientId, percent);
api.ClientChangeVolume(clientId, percentDiff);
Group
api.GroupGetStatus(groupId);
api.GroupSetClients(groupId, clientId1, clientId2);
api.GroupSetClients(groupId, new List<string> { clientId1, clientId2 });
api.GroupSetName(groupId, name);
api.GroupSetMute(groupId, muted);
api.GroupSetStream(groupId, streamId);
Stream
api.StreamAddStream(streamUri); // pipe:///tmp/snapfifo?name=stream1
api.StreamRemoveStream(streamId);
api.OnNotification += OnNotification;
await api.StartNotificationListener();
static void OnNotification(object? sender, IParams @params)
{
Console.WriteLine(@params.GetType());
}
The SnapcastApiException
will be thrown if anything goes wrong.
- API access using http protocol
- Support Snapcast 0.25 API requests and responses
- Support notifications
- Support new Snapcast 0.26 API features (metadata and control api for audio streams)
- (API access using tcp socket)