# Chromecast Support

StreamFlow now supports casting both radio and TV channels to Chromecast devices.

## Features

- **Cast Live TV**: Stream any TV channel directly to your Chromecast device
- **Cast Radio**: Stream radio stations to your Chromecast device
- **Volume Control**: Control volume directly from the app while casting
- **Mute Control**: Mute/unmute the cast stream from the app
- **Visual Feedback**: Clear indication when content is being cast
- **Easy Connect**: Simple one-tap to connect to available Chromecast devices

## How to Use

### TV Channels

1. Open a TV channel in the player
2. Look for the Cast icon (📡) in the bottom control bar
3. Click the Cast icon to open the device selector
4. Select your Chromecast device from the list
5. The stream will start playing on your TV
6. Click the Cast icon again (now highlighted) to stop casting

### Radio Stations

1. Open a radio station in the audio player
2. Look for the Cast icon (📡) next to the volume controls
3. Click the Cast icon to open the device selector
4. Select your Chromecast device from the list
5. The audio will start playing on your Chromecast
6. Click the Cast icon again (now highlighted) to stop casting

## Requirements

- A Chromecast device on the same network
- Modern web browser with Cast support (Chrome, Edge, Opera)
- The Chromecast device must be able to access the StreamFlow server

## Technical Details

### Supported Formats

- **Video**: HLS streams (application/x-mpegURL)
- **Audio**: MP3 and other audio formats (audio/mpeg)

### Cast Receiver

StreamFlow uses the Google Cast Default Media Receiver, which supports:
- Live streaming
- HLS (HTTP Live Streaming)
- Volume control
- Metadata display (title, subtitle, logo)

### Implementation

The Chromecast integration is implemented using:
- **Google Cast SDK**: Loaded from Google's CDN
- **Custom Hook**: `useChromecast()` hook for managing cast sessions
- **Player Integration**: Seamless integration with both VideoPlayer and AudioPlayer components

### Network Considerations

When casting, the Chromecast device connects directly to the StreamFlow backend to fetch the stream. This means:
- The Chromecast must be able to reach the server's IP address
- The stream proxy endpoints must be accessible from the Chromecast device
- Authentication tokens are passed in the stream URL

## Troubleshooting

### Cast Icon Not Appearing

- Ensure you're using a compatible browser (Chrome, Edge, Opera)
- Check that your Chromecast device is powered on and on the same network
- Verify that the Google Cast extension is enabled in your browser

### Cast Connection Fails

- Check that your Chromecast device can reach the StreamFlow server
- Verify firewall settings aren't blocking the connection
- Ensure the stream URL is accessible from the Chromecast device's network

### Audio/Video Not Playing on Chromecast

- The Chromecast may not support the stream format
- Check that the stream URL is accessible (try opening it directly)
- Verify that authentication tokens are being passed correctly

### Controls Not Working

- Volume and mute controls sync with the Chromecast
- Playback controls are managed by the Chromecast device
- If controls are unresponsive, try stopping and restarting the cast session

## Future Enhancements

Potential improvements for Chromecast support:
- Queue support for multiple channels
- Custom Cast receiver with StreamFlow branding
- Enhanced metadata with EPG information
- Picture quality selection for casted streams
- Subtitle/caption support
