百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

SharpCaster

> 数据库
开源

Chromecast C# CLI + SDK

334 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Chromecast C# CLI + SDK

SharpCaster

SharpCaster is a cross-platform toolkit for communicating with Google Chromecast devices. It includes:

  • C# SDK (NuGet): A library for .NET apps to discover, connect, launch apps, and control media on Chromecast devices.
  • Sharpcaster Console (CLI): A cross‑platform command-line app for controlling Chromecast from your terminal, distributed via Chocolatey and Homebrew.

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.

Table of Contents

  • Features
  • Installation
    • C# SDK (NuGet)
    • Sharpcaster Console (CLI)
  • Quick Start
  • Comprehensive Examples
  • Media Queue Management
  • Volume Control
  • Event Handling
  • Custom Chromecast Channels
  • Troubleshooting
  • Contributing
  • License

Features

✅ 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

Installation

C# SDK (NuGet)

Install via NuGet Package Manager:

bash
Install-Package SharpCaster

Or via .NET CLI:

bash
dotnet add package SharpCaster

Sharpcaster Console (CLI)

Control Chromecast devices from your terminal.

  • Homebrew (macOS/Linux):
bash
brew tap Tapanila/sharpcaster
brew install sharpcaster
  • Chocolatey (Windows):
powershell
choco install sharpcaster --pre

After installation, run sharpcaster for interactive mode, or use direct commands like:

bash
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.

Quick Start

1. Discover and Connect to Chromecast

…

2. Launch Application and Play Media

csharp
// 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}");

Comprehensive Examples

Complete Media Player Example

…

Media Queue Management

SharpCaster supports advanced queue operations for playlist-style media playback:

…

Volume Control

csharp
// 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);

Event Handling

SharpCaster provides rich event support for real-time updates:

…

Custom Chromecast Channels

Create custom channels for specialized applications:

…

You can also reverse engineer existing channels:

  1. In Chrome, go to chrome://net-export/
  2. Select 'Include raw bytes (will include cookies and credentials)'
  3. Click 'Start Logging to Disk'
  4. Cast from your favorite web app
  5. Stop logging and open the log in netlog-viewer
  6. Search for type:SOCKET and find familiar JSON data
  7. Collect the exchanged JSON
  8. Create a new class inheriting from ChromecastChannel and implement your logic

Troubleshooting

Common Issues and Solutions

Device Discovery Issues:

csharp
// 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:

csharp
// Enable logging for debugging
var loggerFactory = LoggerFactory.Create(builder => 
    builder.AddConsole().SetMinimumLevel(LogLevel.Debug));
    
var client = new ChromecastClient(loggerFactory);

Media Loading Failures:

  • Ensure media URLs are publicly accessible
  • Verify correct ContentType is specified
  • Check that the Chromecast supports the media format
  • Use HTTPS URLs when possible

Network Issues:

  • Ensure device is on the same network as Chromecast
  • Check firewall settings (port 8009 must be accessible)
  • Verify mDNS/Bonjour is enabled on the network

Error Handling Best Practices

csharp
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}");
}

Demo

Supported Platforms

  • .NET Standard 2.0 - Maximum compatibility across .NET implementations
  • .NET 9 - Latest features including Native AOT support
  • Compatible with: .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5+, Xamarin, Unity

Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Setup

bash
git clone https://github.com/Tapanila/SharpCaster.git
cd SharpCaster
dotnet restore
dotnet build
dotnet test

Testing

Tests require a physical Chromecast device on the network:

bash
dotnet test

Some of the tests may require few tries to pass due to network conditions.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#android-platformaotchromecastchromecast-audio

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库