Chromecast C# CLI + SDK
SharpCaster is a cross-platform toolkit for communicating with Google Chromecast devices. It includes:
C# SDK supports .NET Standard 2.0 and .NET 9 (including Native AOT). Sharpcaster console is built with Native AOT for fast startup, low memory usage and doesn't require .NET installed, works on Windows, macOS, and Linux.
✅ Device Discovery: Automatic discovery of Chromecast devices on your local network using mDNS
✅ Media Control: Complete media playback control (play, pause, stop, seek, volume)
✅ Queue Management: Support for media queues with navigation (next, previous, shuffle, repeat)
✅ Application Management: Launch and manage Chromecast applications
✅ Custom Channels: Extensible architecture for custom Chromecast channels
✅ Cross-Platform: Compatible with .NET Standard 2.0 and .NET 9
✅ AOT Ready: Full support for Native AOT compilation in .NET 9
✅ Async/Await: Modern async programming model throughout
✅ Event-Driven: Rich event system for real-time status updates
Install via NuGet Package Manager:
Install-Package SharpCasterOr via .NET CLI:
dotnet add package SharpCasterControl Chromecast devices from your terminal.
brew tap Tapanila/sharpcaster
brew install sharpcasterchoco install sharpcaster --preAfter installation, run sharpcaster for interactive mode, or use direct commands like:
sharpcaster list
sharpcaster "Living Room TV" play "https://example.com/video.mp4" --title "Sample"For full CLI usage and examples, see SharpCaster.Console/README.md.
…// Launch the default media receiver app
await client.LaunchApplicationAsync("CC1AD845"); // Default Media Receiver
// Create and load media
var media = new Media
{
ContentUrl = "https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4",
ContentType = "video/mp4",
Metadata = new MediaMetadata
{
Title = "Sample Video",
SubTitle = "A demonstration video"
}
};
var mediaStatus = await client.MediaChannel.LoadAsync(media);
Console.WriteLine($"Media loaded: {mediaStatus.PlayerState}");…SharpCaster supports advanced queue operations for playlist-style media playback:
…// Get current volume
var status = await client.ReceiverChannel.GetChromecastStatusAsync();
Console.WriteLine($"Current volume: {status.Volume.Level:P0}");
// Set volume (0.0 to 1.0)
await client.ReceiverChannel.SetVolumeAsync(0.5f);
// Mute/unmute
await client.ReceiverChannel.SetMutedAsync(true);
await client.ReceiverChannel.SetMutedAsync(false);SharpCaster provides rich event support for real-time updates:
…Create custom channels for specialized applications:
…You can also reverse engineer existing channels:
chrome://net-export/type:SOCKET and find familiar JSON dataChromecastChannel and implement your logicDevice Discovery Issues:
// Increase discovery timeout for slow networks
var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token;
var devices = await locator.FindReceiversAsync(cancellationToken);
// Manually specify device if discovery fails
var manualDevice = new ChromecastReceiver
{
Name = "My Chromecast",
DeviceUri = new Uri("http://192.168.1.100"),
Port = 8009
};Connection Timeouts:
// Enable logging for debugging
var loggerFactory = LoggerFactory.Create(builder =>
builder.AddConsole().SetMinimumLevel(LogLevel.Debug));
var client = new ChromecastClient(loggerFactory);Media Loading Failures:
ContentType is specifiedNetwork Issues:
try
{
await client.MediaChannel.LoadAsync(media);
}
catch (TimeoutException)
{
Console.WriteLine("Request timed out - check network connection");
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Invalid operation: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Unexpected error: {ex.Message}");
}We welcome contributions! Here's how you can help:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)git clone https://github.com/Tapanila/SharpCaster.git
cd SharpCaster
dotnet restore
dotnet build
dotnet testTests require a physical Chromecast device on the network:
dotnet testSome of the tests may require few tries to pass due to network conditions.
This project is licensed under the MIT License - see the LICENSE file for details.
暂无开放 Issues,或尚未同步最近议题。