Skip to content

HLS manifest proxy for audio track switching on Tizen 2.3 #2

Description

@stdray

Problem

Tizen 2.3 (Chrome 28) does not support the audioTracks API, and hls.js 0.14 cannot switch audio groups in HLS master playlists. This makes runtime audio track switching impossible for both HTTP and HLS streams.

KPSTV solves this with a lightweight HLS manifest rewriter proxy.

Goal

Implement a minimal HLS manifest proxy that rewrites the master playlist to select a specific audio track and quality, so hls.js on Tizen 2.3 can play the correct audio without needing multi-audio support.

Implementation Plan

1. Proxy endpoint

  • URL: GET /api/hls-proxy.m3u8?url=<base64_hls2_url>&audio=<index>&quality=<value>
  • Parameters:
    • url — base64-encoded HLS2 master playlist URL from KinoPub
    • audio — audio track index (1-based, matches audios[].index from API)
    • qualityauto or specific quality string (e.g. 720p), optional
  • Response: rewritten .m3u8 playlist with correct Content-Type: application/vnd.apple.mpegurl

2. Playlist rewriting logic

  • Fetch the original HLS2 master playlist from KinoPub CDN
  • Parse #EXT-X-MEDIA:TYPE=AUDIO entries — keep only the one matching the requested audio index
  • Parse #EXT-X-STREAM-INF entries:
    • Update AUDIO group reference to point to the remaining audio track
    • If quality is specified (not auto), filter to keep only matching resolution
  • Return the modified playlist
  • Do NOT proxy video/audio segments — they are fetched directly from CDN by the player

3. Hosting options

  • Cloudflare Worker (free tier, simplest, no server needed)
  • Vercel Edge Function
  • Standalone Node.js/Python server

4. Client integration

  • In player.ts, when streaming type is HLS2 and audio switch is requested:
    • Build proxy URL: PROXY_BASE + '/api/hls-proxy.m3u8?url=' + btoa(originalHls2Url) + '&audio=' + audioIndex
    • Reload hls.js with the proxy URL
  • Keep direct HLS4/HLS/HTTP playback unchanged (proxy only needed for audio switching)
  • Add proxy base URL to app settings/config

5. CORS

  • Proxy must return Access-Control-Allow-Origin: * headers
  • KinoPub CDN already serves segments with permissive CORS

6. Caching

  • Cache rewritten playlists for ~30s (same audio+quality+url = same result)
  • No caching of video segments (not proxied)

Complexity estimate

  • Proxy: ~50 lines of code (Cloudflare Worker / Node.js)
  • Client changes: ~20 lines in player.ts
  • Total: small task, biggest part is deployment setup

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions