Commit Graph

10 Commits

Author SHA1 Message Date
xiao 724b0b2a71 feat: new TextDisplayer implementation to allow selecting subtitles via native API and controls (#8520)
Close https://github.com/shaka-project/shaka-player/issues/8519
Fixes https://github.com/shaka-project/shaka-player/issues/8475

Introduce `NativeTextDisplayer` as a replacement of
`SimpleTextDisplayer`. But keep them both work.
Is MSE mode, `NativeTextDisplayer` creates `<track>` elements for text
streams. And listens to change events on both ends to keep them in sync.
In SRC mode, `NativeTextDisplayer` would do nothing, the player uses
original TextTracks instead.

Advantages of `NativeTextDisplayer`:
- Allow text track selection using the browser built-in UI
- Allow text track manipulation using native APIs
- Avoid transferring and processing cues in SRC mode

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
2025-05-07 12:58:29 +02:00
Wojciech Tyczyński 6e55a3b21b build: Forbid using dot in generic types (#7904)
Fixes #2643

Happy reviewing!
2025-01-20 09:39:51 +01:00
PikachuEXE 76376e97f1 fix(WebVTT): Fix mapNativeCueToShakaCue in Chromium browsers (#7273)
Chromium browsers do not currently support the `lineAlign` or
`positionAlign` properties on the VTTCue class, just like the region
property. So this pull request adds an if before reading those
properties so that the position and line values are handled correctly in
UITextDisplayer (without this change the subtitles are always at the
bottom edge of the player and right aligned subtitles are displayed
off-screen).


https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/lineAlign#browser_compatibility

https://developer.mozilla.org/en-US/docs/Web/API/VTTCue/positionAlign#browser_compatibility

Before fix
![Screenshot 2024-09-09 at 08 42
04](https://github.com/user-attachments/assets/b19f223f-0e6e-4678-a1b1-36a759ec9691)
After fix

![image](https://github.com/user-attachments/assets/79854c9d-838b-4b20-9370-4a81407d82fd)

Steps to reproduce:
- Get local demo running (`python build/all.py --debug`?)
- Visit custom content, add
https://d2zihajmogu5jn.cloudfront.net/elephantsdream/ed_hd.mp4 (with
whatever name)
- Add track below
- Start playing custom video, switch Captions to the new text track


**JS to add text track**
```js
await document.getElementById('video').ui.getControls().getPlayer().addTextTrackAsync('data:text/vtt;charset=utf-8,WEBVTT%0AKind%3A%20subtitles%0ALanguage%3A%20en%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20align%3Astart%20position%3A0%25%20line%3A0%25%0ATop%2FLeft%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20line%3A0%25%0ATop%2FCentre%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20align%3Aend%20position%3A100%25%20line%3A0%25%0ATop%2FRight%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20align%3Astart%20position%3A0%25%20line%3A48%25%0AMiddle%2FLeft%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20line%3A48%25%0AMiddle%2FCentre%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20align%3Aend%20position%3A100%25%20line%3A48%25%0AMiddle%2FRight%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20align%3Astart%20position%3A0%25%0ABottom%2FLeft%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%0ABottom%2FCentre%0A%0A00%3A00%3A00.000%20--%3E%2000%3A01%3A00.000%20align%3Aend%20position%3A100%25%0ABottom%2FRight%0A%0A', 'en', 'subtitles', 'text/vtt')
```
2024-09-09 08:56:08 +02:00
Álvaro Velad Galván 3d0b817588 fix: Fix rendering of image subs when using SimpleTextDisplayer (#7258)
This change prevents cues from being created without payload, as is the
case with subtitles in image format.
2024-09-05 15:56:20 +02:00
Wojciech Tyczyński 4f9264637d chore: Add native cue to shaka cue mapping (#7038)
Needed for #6985
2024-07-15 10:14:35 +02:00
Álvaro Velad Galván 516f9f6e97 chore: Move convertToTextTrackCue_ to shaka.text.Utils (#7021)
Also adds a id to all cues.
2024-07-12 07:19:20 +02:00
Álvaro Velad Galván fa9feb346f fix: Filter duplicate cues on text displayer append (#6949) 2024-07-01 20:29:01 +02:00
Álvaro Velad Galván 68903e130e fix: Fix color detection in text utils (#5970) 2023-12-02 08:43:14 +01:00
Albin Larsson ed7a736ca2 feat(webvtt): webvtt colors output (#4954)
Adds color support for SimpleTextDisplayer and WebVttGenerator (only one
place to fix both now thanks to #4941).

It's limited to the [8 colors
classes](https://w3c.github.io/webvtt/#default-text-color) supported by
the WebVTT specification, and also works with their 3 or 6-digit hex
variants (if the stream has TTML subtitles).

It does not support rgb, rgba or any colors other than these 8.

Fixes #4545

---------

Co-authored-by: Alvaro Velad Galvan <ladvan91@hotmail.com>
2023-02-03 09:34:16 +01:00
Álvaro Velad Galván ff80ae67dd chore: Add text_utils.js (#4941) 2023-01-30 18:22:57 +01:00