Skip to content

Feature Request: Google Cast Support via SharpCaster #39

@oca-agent

Description

@oca-agent

I would like to propose adding support for browsing and controlling Google Cast devices within smoc. This would allow users to cast their music to speakers, TVs, and other Cast-enabled devices directly from the CLI.

High-Level Plan

  1. Device Discovery: Integrate SharpCaster to discover devices on the local network.
  2. Audio Service Implementation: Create a new IAudioService implementation (CastAudioService) that targets a selected Cast device.
  3. Playback Service Implementation: Create a CastPlaybackService that implements IPlaybackService to control remote playback.
  4. Local Stream Proxy: Since smoc handles audio as Stream objects, implement a lightweight HTTP proxy to serve these streams to the Cast device.
  5. UI Integration: Implement a command (e.g., :output) to list and select output devices via the command line interface.

Detailed Implementation Plan

1. Core Services

  • ICastDiscoveryService:
    • Task<IEnumerable<Chromecast>> DiscoverDevicesAsync()
    • Uses SharpCaster.DeviceFinder.
  • CastPlaybackService (implements IPlaybackService):
    • Wraps SharpCaster.ChromecastClient and its MediaStatus.
    • Bridges MediaStatus updates to PositionChanged and PlaybackStateChanged events.
    • Implements Play(), Pause(), Stop(), and Seek() by calling the respective SharpCaster methods.
  • CastAudioService (implements IAudioService):
    • Acts as the factory for CastPlaybackService.
    • Manages the connection to the specific Chromecast device.
    • Manages the lifecycle of a local HttpListener to proxy the Stream from IStreamingClient to the Chromecast's required URL.

2. Streaming Proxy

  • A StreamProxyService that:
    • Listens on a random local port.
    • Generates a transient URL (e.g., http://<local-ip>:<port>/stream/<guid>).
    • When the URL is requested, it pipes the Stream from IStreamingClient to the HTTP response.
    • This ensures that any smoc supported stream (Subsonic, etc.) can be played on the Cast device even if the device doesn't have direct access to the source.

3. UI/UX Changes

  • Implement a new command :output in the command bar.
  • Running :output without arguments lists available devices (Local, discovered Cast devices).
  • Running :output <name> (with auto-completion support) switches the active output device.
  • Display the current output device in the status bar or playback info area.
  • Update StandardPlaybackQueueService to switch the underlying IAudioService implementation when a new device is selected via the command.

Dependencies

  • SharpCaster (NuGet) - Latest version (3.0.0)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions