Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] A “tracksDiscovered” or “metadataReady” event would tell you precisely when all audio, subtitle, and quality tracks are available #1370

Open
mohammadozairbarakzay opened this issue Dec 30, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request new issue New issue which has not been checked yet

Comments

@mohammadozairbarakzay
Copy link

Currently, Better Player only provides an initialized event to indicate that playback can start. However, in adaptive streaming scenarios (HLS/DASH), the parsing of track metadata (e.g., subtitles, audio variants, and quality levels) may finish slightly after the player is technically “initialized.” This often forces developers to rely on “hacky” solutions—like manual delays, repeated polling, or retries—to ensure all track data is fully available before showing custom track-selection UI.

Problem

The initialized event doesn’t guarantee that betterPlayerAsmsAudioTracks, betterPlayerSubtitlesSourceList, or betterPlayerAsmsTracks are populated.
Attempts to access these properties immediately after initialized can result in null data, leading to runtime exceptions (e.g., _TypeError (Null check operator used on a null value)) if not carefully handled.
Developers must implement non-trivial delay or retry logic to safely fetch the complete metadata.
Proposed Solution

Introduce a new event—something like metadataReady or tracksDiscovered—fired only when all adaptive track metadata is confirmed loaded and available.
This event would give developers a clear signal to safely fetch and display any audio/subtitle/quality data without concern for null references.
Benefits

Cleaner code: Eliminates the need for manual “delay” or “retry” patterns that are prone to timing issues.
More predictable UX: Ensures custom controls can reliably display a complete list of tracks.
Fewer bugs and exceptions: Minimizes null reference errors and confusion about when metadata is ready.
Potential Implementation

Hook the new event emission into the logic that sets or updates betterPlayerAsmsAudioTracks, betterPlayerSubtitlesSourceList, and betterPlayerAsmsTracks.
Once the library confirms these lists are fully parsed (not null, even if empty), trigger BetterPlayerEventType.metadataReady.
This event could also be refired if the track list changes mid-stream (e.g., live streams or dynamically updated manifests).

@mohammadozairbarakzay mohammadozairbarakzay added enhancement New feature or request new issue New issue which has not been checked yet labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new issue New issue which has not been checked yet
Projects
None yet
Development

No branches or pull requests

2 participants