Overview
ChromeCastService is a singleton service that manages ChromeCast device discovery, connection handling, and remote media playback for Aradia Audiobooks. It provides a Flutter interface to the flutter_chrome_cast plugin.
File: lib/resources/services/chromecast_service.dart
Initialization
initialize()
Initializes the ChromeCast service with default Google Cast settings.This should be called once during app startup (typically in
main.dart). Subsequent calls are ignored.Device Discovery
startDiscovery()
Starts scanning for available ChromeCast devices on the local network.stopDiscovery()
Stops the device discovery process.devicesStream
Stream of discovered ChromeCast devices. Returns:Stream<List<GoogleCastDevice>>
Connection Management
connectToDevice()
Connects to a specific ChromeCast device.The ChromeCast device to connect to
disconnect()
Ends the current ChromeCast session and stops casting.isConnected
Check if currently connected to a ChromeCast device. Returns:bool
sessionStream
Stream of ChromeCast session state changes. Returns:Stream<GoogleCastSession?>
Media Playback
loadAudiobook()
Loads an audiobook into the ChromeCast queue and starts playback.The audiobook to play
List of audio files to queue
Index of the file to start playing
Position within the file to start playback
The service automatically creates a queue with metadata including title, author, and cover art for each audio file.
Playback Controls
play() Resumes playback on the ChromeCast device.The position to seek to
Media Status Monitoring
mediaStatusStream
Stream of media playback status updates. Returns:Stream<GoggleCastMediaStatus?>
currentPosition
Get the current playback position. Returns:Duration
Cleanup
dispose()
Cancels all subscriptions and stops device discovery. Call when the service is no longer needed.Integration Example
Related
- MyAudioHandler - Integrates with ChromeCast for unified playback control
- Audiobook Player Screen - UI for ChromeCast controls