# Chromecast / Smart TV

> Cast video from the app to a TV.

- **Applies to:** AppMint and Appwright
- **Source:** the Integration Guide shipped inside the app; this page is generated from it.
- **HTML:** https://freewebtoapk.com/docs/chromecast-and-smart-tv

Cast Web Content to TV via JS Bridge

### 1. What is Chromecast Support?

Chromecast support lets users cast video/audio from your app to a TV or smart display. The app provides a JavaScript bridge that your website can call to initiate casting.

Perfect for:

- Video streaming websites
- Music platforms
- Photo galleries
- Presentation tools
- Digital signage control apps

### 2. How It Works

The generated app injects a JavaScript bridge (window.WebToApk) into your WebView. Your website can call this bridge to trigger native Android casting.

Flow:

1. User taps a 'Cast' button on your website
2. Your JS calls window.WebToApk.castMedia(url)
3. Android opens the native media sharing/casting chooser
4. User selects their Chromecast device
5. Media plays on the TV

### 3. Add Cast Button to Your Website

Add a Cast button to your website that calls the JS bridge:

```
<!-- Add a Cast button -->
<button id="castBtn" onclick="castToTV()">
  📺 Cast to TV
</button>

<script>
function castToTV() {
  var videoUrl = document.querySelector('video')?.src
    || 'https://yoursite.com/video.mp4';
  
  if (window.WebToApk && window.WebToApk.castMedia) {
    window.WebToApk.castMedia(videoUrl);
  } else {
    alert('Casting is only available in the app');
  }
}
</script>
```

### 4. Supported Media Types

The cast bridge supports these media types:

✅ Direct video URLs (MP4, WebM)  
✅ Audio URLs (MP3, AAC, OGG)  
✅ HLS streams (.m3u8)  
✅ DASH streams (.mpd)

⚠️ DRM-protected content requires additional Chromecast receiver app setup

⚠️ Web pages (HTML) cannot be cast directly - only media URLs

### 5. Detect App Environment

Your website can detect whether it's running inside the generated app to show/hide the cast button:

```
// Check if running inside WebToApk app
if (window.WebToApk) {
  // Running in the app — show cast button
  document.getElementById('castBtn')
    .style.display = 'block';
} else {
  // Running in a browser — hide cast button
  document.getElementById('castBtn')
    .style.display = 'none';
}
```

### 6. Fallback for Browser

If your website is also accessed from a regular browser, the window.WebToApk object won't exist. Always check before calling:

✅ Use feature detection: if (window.WebToApk)  
✅ Provide a fallback message for browser users  
✅ Consider showing a 'Download our app for casting' banner

