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
- Device Discovery: Integrate
SharpCaster to discover devices on the local network.
- Audio Service Implementation: Create a new
IAudioService implementation (CastAudioService) that targets a selected Cast device.
- Playback Service Implementation: Create a
CastPlaybackService that implements IPlaybackService to control remote playback.
- Local Stream Proxy: Since
smoc handles audio as Stream objects, implement a lightweight HTTP proxy to serve these streams to the Cast device.
- 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)
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
SharpCasterto discover devices on the local network.IAudioServiceimplementation (CastAudioService) that targets a selected Cast device.CastPlaybackServicethat implementsIPlaybackServiceto control remote playback.smochandles audio asStreamobjects, implement a lightweight HTTP proxy to serve these streams to the Cast device.:output) to list and select output devices via the command line interface.Detailed Implementation Plan
1. Core Services
ICastDiscoveryService:Task<IEnumerable<Chromecast>> DiscoverDevicesAsync()SharpCaster.DeviceFinder.CastPlaybackService(implementsIPlaybackService):SharpCaster.ChromecastClientand itsMediaStatus.MediaStatusupdates toPositionChangedandPlaybackStateChangedevents.Play(),Pause(),Stop(), andSeek()by calling the respectiveSharpCastermethods.CastAudioService(implementsIAudioService):CastPlaybackService.HttpListenerto proxy theStreamfromIStreamingClientto the Chromecast's required URL.2. Streaming Proxy
StreamProxyServicethat:http://<local-ip>:<port>/stream/<guid>).StreamfromIStreamingClientto the HTTP response.smocsupported 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
:outputin the command bar.:outputwithout arguments lists available devices (Local, discovered Cast devices).:output <name>(with auto-completion support) switches the active output device.StandardPlaybackQueueServiceto switch the underlyingIAudioServiceimplementation when a new device is selected via the command.Dependencies
SharpCaster(NuGet) - Latest version (3.0.0)