Skip to content

fix: emit TEXT_TRACK_CHANGE event when changing subtitles in ShakaTech - #130

Merged
birme merged 1 commit into
masterfrom
fix/shakatech-texttrack-change-event
Feb 12, 2026
Merged

birme merged 1 commit into
masterfrom
fix/shakatech-texttrack-change-event

Conversation

@alexbj75

Copy link
Copy Markdown
Contributor

Problem

When using ShakaTech (DASH streams) with the Eyevinn player skin, changing subtitles through the UI doesn't update the displayed text track. The subtitle selector shows available tracks, but selecting a different subtitle has no visible effect.

Root Cause

ShakaTech's textTrack setter successfully calls Shaka Player's selectTextTrack() and setTextTrackVisibility() methods to change the active subtitle, but it never emits the TEXT_TRACK_CHANGE event. This means:

  • Player state is never updated with the new text track selection
  • UI never receives notification via STATE_CHANGE event
  • Other components listening for text track changes are not notified

While the subtitle may technically change in Shaka Player internally, the player's state management system remains unaware.

Solution

Add onTextTrackChange() calls after changing tracks in the textTrack setter, following the same pattern already used for audio track changes (line 91).

Changes:

  • Line 114: Added this.onTextTrackChange(); after enabling a text track
  • Line 117: Added this.onTextTrackChange(); after disabling text tracks

This ensures:

  • State is updated via updateState({ textTracks: this.textTracks })
  • TEXT_TRACK_CHANGE event is emitted
  • Player relays STATE_CHANGE event to UI

Why This Fix Works

  1. Follows Existing Pattern: BaseTech already provides the onTextTrackChange() infrastructure
  2. Consistent with Audio Tracks: ShakaTech already calls onAudioTrackChange() after changing audio tracks (line 91)
  3. Minimal Changes: Only 2 lines added, no architectural changes
  4. Safe: The method is designed to be called manually when the underlying player changes tracks
  5. Complete: Handles both enabling a track and disabling all tracks

Reference Implementation

HlsJsTech (HLS streams) correctly handles this by registering an event listener:

this.hls.on(Hls.Events.SUBTITLE_TRACK_SWITCH, this.onTextTrackChange.bind(this));

ShakaTech's audio tracks already follow the manual trigger pattern:

set audioTrack(trackId) {
  // ... change track logic ...
  this.onAudioTrackChange(); // ✅ Already does this!
}

Testing

Manual Verification

  1. Build: npm run build
  2. Run demo: npm run examples
  3. Load a DASH stream with multiple subtitle tracks
  4. Change between different subtitle tracks via the UI
  5. Expected: Subtitles should change on the video
  6. Expected: TEXT_TRACK_CHANGE events should appear in console

Code Verification

player.on('text_track_change', (track) => {
  console.log('Text track changed to:', track);
});

Risk Assessment

Low Risk:

  • Minimal code change (2 lines)
  • Uses existing, tested infrastructure (onTextTrackChange() from BaseTech)
  • Follows established pattern (audio tracks already work this way)
  • No breaking changes to API
  • Only affects ShakaTech/DASH playback

Related Issues

This may be related to or help resolve:

🤖 Generated with Claude Code

Problem:
When using ShakaTech (DASH streams) with the Eyevinn player skin, changing
subtitles through the UI doesn't update the displayed text track. The subtitle
selector shows available tracks, but selecting a different subtitle has no
visible effect.

Root Cause:
ShakaTech's textTrack setter successfully calls Shaka Player's
selectTextTrack() and setTextTrackVisibility() to change the active subtitle,
but never emits the TEXT_TRACK_CHANGE event. This means:
- Player state is never updated with the new text track selection
- UI never receives notification via STATE_CHANGE event
- Other components listening for text track changes are not notified

Solution:
Add onTextTrackChange() calls after changing tracks in the setter, following
the same pattern already used for audio track changes (line 91). This ensures:
- State is updated via updateState({ textTracks: this.textTracks })
- TEXT_TRACK_CHANGE event is emitted
- Player relays STATE_CHANGE event to UI

This fix follows the existing pattern used by:
- ShakaTech's audioTrack setter (already calls onAudioTrackChange())
- HlsJsTech's text track handling (registers event listener)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@birme
birme merged commit d99ffb0 into master Feb 12, 2026
2 checks passed
birme added a commit that referenced this pull request Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants