# abcc_roku
abcc roku development

## Overview

**App:** Arabic Bible Christian Channel (ABCC) - a Roku SceneGraph channel app.

## Key Files

| File | Purpose |
|------|---------|
| `manifest` | App metadata — title, version, icons, splash screen |
| `source/main.brs` | Entry point — creates screen, handles deep linking |
| `components/MainScene.xml/.brs` | Root scene — initializes grid, content task, back navigation |
| `components/tasks/MainLoaderTask.brs` | Fetches content feed from `https://media.abcc.org/roku/feeds/primary-feed.json` |
| `components/UILogic/` | Screen stack, grid, video player, content task logic |
| `components/GridScreen/` | Grid UI component |

## Architecture

- SceneGraph-based Roku app
- Fetches a JSON content feed and builds a RowList/grid of videos
- Supports deep linking via `contentid` + `mediaType` args
- Video playback via `VideoPlayerLogic.brs`

## Features

### Watch Live
A **WATCH LIVE** button is displayed in the top-right of the overhang header on the main grid screen.

**Navigation:**
- Press **Up** from the video grid → focus moves to the WATCH LIVE button (highlights red)
- Press **OK** → launches the live HLS stream immediately
- Press **Down** or **Back** on the button → returns focus to the grid

**Implementation:**
- Live stream URL is defined as a constant at the top of `components/UILogic/VideoPlayerLogic.brs`:
  ```
  LIVE_STREAM_URL = "https://media.abcc.org/live/stream.m3u8"
  ```
  Update this to your actual HLS endpoint.
- Uses a dedicated `OnLivePlayerStateChange()` handler — retries up to 5x on error, never closes on `"finished"` (live streams have no end)
- `contentIsPlaylist = false` to prevent premature stream closure

### Video Playback Error Handling
On VOD playback error, the player retries up to 3 times before closing. The retry counter resets on successful playback, so transient drops recover cleanly.

## Server — Live Stream Endpoint

The "Watch Live" stream is a **scheduled playout** of pre-recorded videos
served as a continuous HLS stream — no camera or encoder required.

**How it works:**
1. `abcc-live` service reads `schedule.json` to find the current block
2. Locates the correct video file(s) in `/var/www/html/media/videos/`
3. Calculates how far into the block we are and seeks to that position
4. FFmpeg plays the video(s) out as HLS segments
5. When FFmpeg exits (video ends), the loop recalculates and continues
6. Apache serves `https://media.abcc.org/live/stream.m3u8` to Roku/browsers

**Start / stop:**
```bash
sudo systemctl start abcc-live
sudo systemctl stop abcc-live
sudo journalctl -u abcc-live -f   # live logs
```

**Key server files:**

| Path | Purpose |
|------|---------|
| `scripts/start_live_stream.sh` | Scheduled playout engine (FFmpeg loop) |
| `scripts/update_now_playing.sh` | Updates now-playing.json every 5 min (cron) |
| `/etc/systemd/system/abcc-live.service` | Systemd service (auto-restarts on failure) |
| `/var/www/html/media/live/.htaccess` | HLS MIME types, no-cache, CORS headers |

## Notes

- There is a duplicate `GetContent()` function in `components/tasks/MainLoaderTask.brs` (lines 15 and 148). The first calls `GetContentJdon()` (the active one); the second at line 148 is dead code and can be removed.
