@banou/media-player 0.10.34 → 0.10.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -8
- package/dist/cs-CxBZ1aTx.js +52 -0
- package/dist/el-BVTNfAWK.js +52 -0
- package/dist/hi-rBroV7g8.js +52 -0
- package/dist/hu-m-QKaaxF.js +52 -0
- package/dist/id-BYpApdK9.js +52 -0
- package/dist/index.js +615 -599
- package/dist/language/index.d.ts +39 -5
- package/dist/language/index.js +53 -18
- package/dist/ms-8pQbqM0D.js +52 -0
- package/dist/nl-q7xvc3xW.js +52 -0
- package/dist/react/video-player.d.ts +18 -2
- package/dist/ro-DBrd08Df.js +52 -0
- package/dist/sv-DJC3tXfW.js +52 -0
- package/dist/th-BNzU_FYo.js +52 -0
- package/dist/uk-C66esN2W.js +52 -0
- package/dist/vi-oOaDECwu.js +52 -0
- package/package.json +1 -1
- package/src/lib/language/index.ts +94 -13
- package/src/lib/locales/cs.json +49 -0
- package/src/lib/locales/el.json +49 -0
- package/src/lib/locales/hi.json +49 -0
- package/src/lib/locales/hu.json +49 -0
- package/src/lib/locales/id.json +49 -0
- package/src/lib/locales/ms.json +49 -0
- package/src/lib/locales/nl.json +49 -0
- package/src/lib/locales/ro.json +49 -0
- package/src/lib/locales/sv.json +49 -0
- package/src/lib/locales/th.json +49 -0
- package/src/lib/locales/uk.json +49 -0
- package/src/lib/locales/vi.json +49 -0
- package/src/lib/react/hooks/use-playback.ts +20 -19
- package/src/lib/react/labels.tsx +12 -0
- package/src/lib/react/video-player.tsx +26 -7
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"(Default)": "(ปกติ)",
|
|
3
|
+
"Audio": "เสียง",
|
|
4
|
+
"Copied": "คัดลอกแล้ว",
|
|
5
|
+
"Copy": "คัดลอก",
|
|
6
|
+
"Copy the errors": "คัดลอกข้อผิดพลาด",
|
|
7
|
+
"Could not switch. Try again.": "สลับไม่สำเร็จ ลองอีกครั้ง",
|
|
8
|
+
"Disable": "ปิด",
|
|
9
|
+
"Exit full screen (f)": "ออกจากโหมดเต็มหน้าจอ (f)",
|
|
10
|
+
"Exit picture in picture": "ออกจากภาพซ้อนภาพ",
|
|
11
|
+
"Full screen": "เต็มหน้าจอ",
|
|
12
|
+
"Full screen (f)": "เต็มหน้าจอ (f)",
|
|
13
|
+
"Mute": "ปิดเสียง",
|
|
14
|
+
"Mute (m)": "ปิดเสียง (m)",
|
|
15
|
+
"Normalize volume": "ปรับระดับเสียงให้เท่ากัน",
|
|
16
|
+
"Now click your browser's pop out button": "ตอนนี้ให้คลิกปุ่มภาพซ้อนภาพของเบราว์เซอร์",
|
|
17
|
+
"Pause": "หยุดชั่วคราว",
|
|
18
|
+
"Pause (k)": "หยุดชั่วคราว (k)",
|
|
19
|
+
"Picture in picture": "ภาพซ้อนภาพ",
|
|
20
|
+
"Play": "เล่น",
|
|
21
|
+
"Play (k)": "เล่น (k)",
|
|
22
|
+
"Playback errors ({count})": "ข้อผิดพลาดในการเล่น ({count})",
|
|
23
|
+
"Playback failed": "เล่นไม่สำเร็จ",
|
|
24
|
+
"Playback speed": "ความเร็วในการเล่น",
|
|
25
|
+
"Put the subtitles in the picture": "ฝังคำบรรยายลงในภาพ",
|
|
26
|
+
"Put the subtitles in the video": "ฝังคำบรรยายลงในวิดีโอ",
|
|
27
|
+
"Quality": "คุณภาพ",
|
|
28
|
+
"Reading the video file failed": "อ่านไฟล์วิดีโอไม่สำเร็จ",
|
|
29
|
+
"Replay": "เล่นอีกครั้ง",
|
|
30
|
+
"Replay (k)": "เล่นอีกครั้ง (k)",
|
|
31
|
+
"Settings": "การตั้งค่า",
|
|
32
|
+
"Skip Ending": "ข้ามเพลงปิด",
|
|
33
|
+
"Skip Opening": "ข้ามเพลงเปิด",
|
|
34
|
+
"Subtitles": "คำบรรยาย",
|
|
35
|
+
"Subtitles are in the picture": "คำบรรยายอยู่ในภาพแล้ว",
|
|
36
|
+
"The MediaSource closed before a SourceBuffer could be created": "MediaSource ปิดไปก่อนที่จะสร้าง SourceBuffer ได้",
|
|
37
|
+
"The MediaSource never opened": "MediaSource ไม่เคยเปิด",
|
|
38
|
+
"The browser rejected a media segment": "เบราว์เซอร์ปฏิเสธส่วนหนึ่งของสื่อ",
|
|
39
|
+
"The video codec in this file could not be identified": "ระบุตัวแปลงสัญญาณวิดีโอของไฟล์นี้ไม่ได้",
|
|
40
|
+
"This browser cannot play the codecs in this file: {codecs}": "เบราว์เซอร์นี้เล่นตัวแปลงสัญญาณของไฟล์นี้ไม่ได้: {codecs}",
|
|
41
|
+
"This file has no subtitles": "ไฟล์นี้ไม่มีคำบรรยาย",
|
|
42
|
+
"Track {number}": "แทร็ก {number}",
|
|
43
|
+
"Unavailable": "ไม่พร้อมใช้งาน",
|
|
44
|
+
"Unmute (m)": "เปิดเสียง (m)",
|
|
45
|
+
"at {time}": "ที่ {time}",
|
|
46
|
+
"recovered": "กู้คืนแล้ว",
|
|
47
|
+
"{rate}x": "{rate}x",
|
|
48
|
+
"{start} to {end}": "{start} ถึง {end}"
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"(Default)": "(Звичайна)",
|
|
3
|
+
"Audio": "Аудіо",
|
|
4
|
+
"Copied": "Скопійовано",
|
|
5
|
+
"Copy": "Копіювати",
|
|
6
|
+
"Copy the errors": "Копіювати помилки",
|
|
7
|
+
"Could not switch. Try again.": "Не вдалося перемкнути. Спробуйте ще раз.",
|
|
8
|
+
"Disable": "Вимкнено",
|
|
9
|
+
"Exit full screen (f)": "Вийти з повноекранного режиму (f)",
|
|
10
|
+
"Exit picture in picture": "Вийти з режиму «картинка в картинці»",
|
|
11
|
+
"Full screen": "На весь екран",
|
|
12
|
+
"Full screen (f)": "На весь екран (f)",
|
|
13
|
+
"Mute": "Вимкнути звук",
|
|
14
|
+
"Mute (m)": "Вимкнути звук (m)",
|
|
15
|
+
"Normalize volume": "Вирівнювати гучність",
|
|
16
|
+
"Now click your browser's pop out button": "Тепер натисніть кнопку «картинка в картинці» у браузері",
|
|
17
|
+
"Pause": "Пауза",
|
|
18
|
+
"Pause (k)": "Пауза (k)",
|
|
19
|
+
"Picture in picture": "Картинка в картинці",
|
|
20
|
+
"Play": "Відтворити",
|
|
21
|
+
"Play (k)": "Відтворити (k)",
|
|
22
|
+
"Playback errors ({count})": "Помилки відтворення ({count})",
|
|
23
|
+
"Playback failed": "Не вдалося відтворити",
|
|
24
|
+
"Playback speed": "Швидкість",
|
|
25
|
+
"Put the subtitles in the picture": "Вбудувати субтитри в зображення",
|
|
26
|
+
"Put the subtitles in the video": "Вбудувати субтитри у відео",
|
|
27
|
+
"Quality": "Якість",
|
|
28
|
+
"Reading the video file failed": "Не вдалося прочитати відеофайл",
|
|
29
|
+
"Replay": "Дивитися знову",
|
|
30
|
+
"Replay (k)": "Дивитися знову (k)",
|
|
31
|
+
"Settings": "Налаштування",
|
|
32
|
+
"Skip Ending": "Пропустити титри",
|
|
33
|
+
"Skip Opening": "Пропустити заставку",
|
|
34
|
+
"Subtitles": "Субтитри",
|
|
35
|
+
"Subtitles are in the picture": "Субтитри вбудовано в зображення",
|
|
36
|
+
"The MediaSource closed before a SourceBuffer could be created": "MediaSource закрився до того, як вдалося створити SourceBuffer",
|
|
37
|
+
"The MediaSource never opened": "MediaSource так і не відкрився",
|
|
38
|
+
"The browser rejected a media segment": "Браузер відхилив медіасегмент",
|
|
39
|
+
"The video codec in this file could not be identified": "Не вдалося визначити відеокодек цього файлу",
|
|
40
|
+
"This browser cannot play the codecs in this file: {codecs}": "Цей браузер не може відтворити кодеки цього файлу: {codecs}",
|
|
41
|
+
"This file has no subtitles": "У цьому файлі немає субтитрів",
|
|
42
|
+
"Track {number}": "Доріжка {number}",
|
|
43
|
+
"Unavailable": "Недоступно",
|
|
44
|
+
"Unmute (m)": "Увімкнути звук (m)",
|
|
45
|
+
"at {time}": "на {time}",
|
|
46
|
+
"recovered": "відновлено",
|
|
47
|
+
"{rate}x": "{rate}x",
|
|
48
|
+
"{start} to {end}": "з {start} до {end}"
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"(Default)": "(Mặc định)",
|
|
3
|
+
"Audio": "Âm thanh",
|
|
4
|
+
"Copied": "Đã sao chép",
|
|
5
|
+
"Copy": "Sao chép",
|
|
6
|
+
"Copy the errors": "Sao chép lỗi",
|
|
7
|
+
"Could not switch. Try again.": "Không chuyển được. Hãy thử lại.",
|
|
8
|
+
"Disable": "Tắt",
|
|
9
|
+
"Exit full screen (f)": "Thoát toàn màn hình (f)",
|
|
10
|
+
"Exit picture in picture": "Thoát hình trong hình",
|
|
11
|
+
"Full screen": "Toàn màn hình",
|
|
12
|
+
"Full screen (f)": "Toàn màn hình (f)",
|
|
13
|
+
"Mute": "Tắt tiếng",
|
|
14
|
+
"Mute (m)": "Tắt tiếng (m)",
|
|
15
|
+
"Normalize volume": "Cân bằng âm lượng",
|
|
16
|
+
"Now click your browser's pop out button": "Bây giờ hãy nhấp vào nút hình trong hình của trình duyệt",
|
|
17
|
+
"Pause": "Tạm dừng",
|
|
18
|
+
"Pause (k)": "Tạm dừng (k)",
|
|
19
|
+
"Picture in picture": "Hình trong hình",
|
|
20
|
+
"Play": "Phát",
|
|
21
|
+
"Play (k)": "Phát (k)",
|
|
22
|
+
"Playback errors ({count})": "Lỗi phát ({count})",
|
|
23
|
+
"Playback failed": "Không phát được",
|
|
24
|
+
"Playback speed": "Tốc độ phát",
|
|
25
|
+
"Put the subtitles in the picture": "Gắn phụ đề vào hình",
|
|
26
|
+
"Put the subtitles in the video": "Gắn phụ đề vào video",
|
|
27
|
+
"Quality": "Chất lượng",
|
|
28
|
+
"Reading the video file failed": "Không đọc được tệp video",
|
|
29
|
+
"Replay": "Phát lại",
|
|
30
|
+
"Replay (k)": "Phát lại (k)",
|
|
31
|
+
"Settings": "Cài đặt",
|
|
32
|
+
"Skip Ending": "Bỏ qua đoạn kết",
|
|
33
|
+
"Skip Opening": "Bỏ qua đoạn mở đầu",
|
|
34
|
+
"Subtitles": "Phụ đề",
|
|
35
|
+
"Subtitles are in the picture": "Phụ đề đã nằm trong hình",
|
|
36
|
+
"The MediaSource closed before a SourceBuffer could be created": "MediaSource đã đóng trước khi tạo được SourceBuffer",
|
|
37
|
+
"The MediaSource never opened": "MediaSource chưa bao giờ mở",
|
|
38
|
+
"The browser rejected a media segment": "Trình duyệt đã từ chối một đoạn phương tiện",
|
|
39
|
+
"The video codec in this file could not be identified": "Không xác định được codec video của tệp này",
|
|
40
|
+
"This browser cannot play the codecs in this file: {codecs}": "Trình duyệt này không phát được codec của tệp này: {codecs}",
|
|
41
|
+
"This file has no subtitles": "Tệp này không có phụ đề",
|
|
42
|
+
"Track {number}": "Rãnh {number}",
|
|
43
|
+
"Unavailable": "Không khả dụng",
|
|
44
|
+
"Unmute (m)": "Bật tiếng (m)",
|
|
45
|
+
"at {time}": "tại {time}",
|
|
46
|
+
"recovered": "đã khôi phục",
|
|
47
|
+
"{rate}x": "{rate}x",
|
|
48
|
+
"{start} to {end}": "{start} đến {end}"
|
|
49
|
+
}
|
|
@@ -8,7 +8,7 @@ import { isMediaElementError, startPlayback } from '../../engine'
|
|
|
8
8
|
import { usePlayer } from '../player'
|
|
9
9
|
import { useLabels } from '../labels'
|
|
10
10
|
import { toNamedTracks } from '../../utils/track-label'
|
|
11
|
-
import { languageOf,
|
|
11
|
+
import { languageOf, playsIn, startingTracks } from '../../language'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* A wedged element is rebuilt, however many times it takes.
|
|
@@ -42,13 +42,6 @@ const SEEK_PREPARE_BUDGET_MS = 500
|
|
|
42
42
|
*/
|
|
43
43
|
const SEEK_DISPLAY_LIMIT_MS = 15_000
|
|
44
44
|
|
|
45
|
-
/** The subtitle stream a media starts on: the first in the preferred language, else the first; none when it is off. */
|
|
46
|
-
const preferredSubtitle = (preference: string | null | undefined, subtitles: SubtitleStream[]) => {
|
|
47
|
-
if (preference === null) return undefined
|
|
48
|
-
const index = preference === undefined ? 0 : preferredTrack(preference, subtitles)
|
|
49
|
-
return subtitles[Math.max(index, 0)]?.streamIndex
|
|
50
|
-
}
|
|
51
|
-
|
|
52
45
|
const messageOf = (error: unknown) =>
|
|
53
46
|
error instanceof Error ? error.message : String(error)
|
|
54
47
|
|
|
@@ -153,17 +146,24 @@ export const usePlayback = (
|
|
|
153
146
|
const sizeRef = useRef(size)
|
|
154
147
|
sizeRef.current = size
|
|
155
148
|
const streams = useRef<{ audio: AudioStream[], subtitles: SubtitleStream[] }>({ audio: [], subtitles: [] })
|
|
149
|
+
const playingAudio = useCallback(() => streams.current.audio.find((track) => track.streamIndex === player.selectedAudioTrack), [player])
|
|
156
150
|
|
|
157
151
|
const readRef = useRef(read)
|
|
158
152
|
readRef.current = read
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
153
|
+
const preferences = {
|
|
154
|
+
audio: options?.preferredAudioLanguage,
|
|
155
|
+
original: options?.originalLanguage,
|
|
156
|
+
subtitles: options?.preferredSubtitleLanguage,
|
|
157
|
+
alwaysSubtitles: options?.alwaysShowSubtitles,
|
|
158
|
+
}
|
|
159
|
+
const preferencesRef = useRef(preferences)
|
|
160
|
+
preferencesRef.current = preferences
|
|
163
161
|
const onAudioLanguageRef = useRef(options?.onPreferredAudioLanguageChange)
|
|
164
162
|
onAudioLanguageRef.current = options?.onPreferredAudioLanguageChange
|
|
165
163
|
const onSubtitleLanguageRef = useRef(options?.onPreferredSubtitleLanguageChange)
|
|
166
164
|
onSubtitleLanguageRef.current = options?.onPreferredSubtitleLanguageChange
|
|
165
|
+
const onAlwaysSubtitlesRef = useRef(options?.onAlwaysShowSubtitlesChange)
|
|
166
|
+
onAlwaysSubtitlesRef.current = options?.onAlwaysShowSubtitlesChange
|
|
167
167
|
const onSeekRef = useRef(options?.onSeek)
|
|
168
168
|
onSeekRef.current = options?.onSeek
|
|
169
169
|
const onPlaybackErrorRef = useRef(options?.onPlaybackError)
|
|
@@ -193,7 +193,8 @@ export const usePlayback = (
|
|
|
193
193
|
? null
|
|
194
194
|
: languageOf(stream) ?? (wasOff ? stream?.title?.trim() || 'und' : undefined)
|
|
195
195
|
if (language !== undefined) onSubtitleLanguageRef.current?.(language)
|
|
196
|
-
|
|
196
|
+
if (language && playsIn(playingAudio(), language)) onAlwaysSubtitlesRef.current?.(true)
|
|
197
|
+
}, [player, playingAudio])
|
|
197
198
|
|
|
198
199
|
/**
|
|
199
200
|
* Seek with the data already there, or after the deadline, whichever comes first.
|
|
@@ -382,10 +383,7 @@ export const usePlayback = (
|
|
|
382
383
|
cjkFontUrl,
|
|
383
384
|
bufferSize,
|
|
384
385
|
audioStreamIndex,
|
|
385
|
-
chooseAudioStream: (audio) =>
|
|
386
|
-
const preference = preferredAudioRef.current
|
|
387
|
-
return preference === undefined ? undefined : audio[preferredTrack(preference, audio)]?.streamIndex
|
|
388
|
-
},
|
|
386
|
+
chooseAudioStream: (audio) => audio[startingTracks(audio, [], preferencesRef.current).audio]?.streamIndex,
|
|
389
387
|
onReady: () => {
|
|
390
388
|
if (cancelled) return
|
|
391
389
|
player.setSourceState({ ready: true })
|
|
@@ -404,9 +402,12 @@ export const usePlayback = (
|
|
|
404
402
|
onSubtitleStreams: (subtitles) => {
|
|
405
403
|
if (cancelled) return
|
|
406
404
|
streams.current.subtitles = subtitles
|
|
405
|
+
// for the audio playing, which may be one the viewer picked
|
|
406
|
+
const playing = playingAudio()
|
|
407
|
+
const start = startingTracks(playing ? [playing] : [], subtitles, preferencesRef.current).subtitles
|
|
407
408
|
player.setSourceState({
|
|
408
409
|
subtitleTracks: toNamedTracks(subtitles, labelsRef.current),
|
|
409
|
-
...subtitleChoiceFor.current === size ? {} : { selectedSubtitleTrack:
|
|
410
|
+
...subtitleChoiceFor.current === size ? {} : { selectedSubtitleTrack: start === null ? undefined : subtitles[Math.max(start, 0)]?.streamIndex },
|
|
410
411
|
})
|
|
411
412
|
},
|
|
412
413
|
onAudioStreams: (audio, selected) => {
|
|
@@ -445,7 +446,7 @@ export const usePlayback = (
|
|
|
445
446
|
// identity. A streaming consumer passes a fresh closure on every state update, which is several
|
|
446
447
|
// times a second, and the restart loop reads as "Loading metadata" forever at a flat 0 B/s.
|
|
447
448
|
}, [
|
|
448
|
-
player, video, subtitles, size, publicPath, libavWorkerUrl, jassubWorkerUrl, jassubWasmUrl,
|
|
449
|
+
player, playingAudio, video, subtitles, size, publicPath, libavWorkerUrl, jassubWorkerUrl, jassubWasmUrl,
|
|
449
450
|
jassubLegacyWasmUrl, defaultFontUrl, cjkFontUrl, bufferSize, audioStreamIndex, autoplay, restartToken,
|
|
450
451
|
])
|
|
451
452
|
}
|
package/src/lib/react/labels.tsx
CHANGED
|
@@ -11,17 +11,29 @@ type Catalogue = Readonly<Record<string, string>>
|
|
|
11
11
|
// One chunk per language, fetched with FormatJS by the first player shown in it, so a player in English loads neither.
|
|
12
12
|
const CATALOGUES: Readonly<Record<string, () => Promise<{ default: Catalogue }>>> = {
|
|
13
13
|
'ar': () => import('../locales/ar.json'),
|
|
14
|
+
'cs': () => import('../locales/cs.json'),
|
|
14
15
|
'de': () => import('../locales/de.json'),
|
|
16
|
+
'el': () => import('../locales/el.json'),
|
|
15
17
|
'es-419': () => import('../locales/es-419.json'),
|
|
16
18
|
'fr': () => import('../locales/fr.json'),
|
|
17
19
|
'he': () => import('../locales/he.json'),
|
|
20
|
+
'hi': () => import('../locales/hi.json'),
|
|
21
|
+
'hu': () => import('../locales/hu.json'),
|
|
22
|
+
'id': () => import('../locales/id.json'),
|
|
18
23
|
'it': () => import('../locales/it.json'),
|
|
19
24
|
'ja': () => import('../locales/ja.json'),
|
|
20
25
|
'ko': () => import('../locales/ko.json'),
|
|
26
|
+
'ms': () => import('../locales/ms.json'),
|
|
27
|
+
'nl': () => import('../locales/nl.json'),
|
|
21
28
|
'pl': () => import('../locales/pl.json'),
|
|
22
29
|
'pt-BR': () => import('../locales/pt-BR.json'),
|
|
30
|
+
'ro': () => import('../locales/ro.json'),
|
|
23
31
|
'ru': () => import('../locales/ru.json'),
|
|
32
|
+
'sv': () => import('../locales/sv.json'),
|
|
33
|
+
'th': () => import('../locales/th.json'),
|
|
24
34
|
'tr': () => import('../locales/tr.json'),
|
|
35
|
+
'uk': () => import('../locales/uk.json'),
|
|
36
|
+
'vi': () => import('../locales/vi.json'),
|
|
25
37
|
'zh-Hans': () => import('../locales/zh-Hans.json'),
|
|
26
38
|
'zh-Hant': () => import('../locales/zh-Hant.json'),
|
|
27
39
|
}
|
|
@@ -19,7 +19,7 @@ import { useVolumeNormalizer } from './hooks/use-volume-normalizer'
|
|
|
19
19
|
import { createPlaybackTap } from '../audio/playback-tap'
|
|
20
20
|
import Chrome from './components/chrome'
|
|
21
21
|
import { LabelsProvider } from './labels'
|
|
22
|
-
import { languageOf } from '../language'
|
|
22
|
+
import { languageOf, playsIn } from '../language'
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* The source, read a range at a time: the player never downloads the whole file. Both fields travel
|
|
@@ -169,6 +169,11 @@ type CommonOptions = {
|
|
|
169
169
|
* with them on too.
|
|
170
170
|
*/
|
|
171
171
|
onPreferredSubtitleLanguageChange?: (language: string | null) => void
|
|
172
|
+
/**
|
|
173
|
+
* True when the viewer picked subtitles in the language the audio plays in: what an app saves to pass back as
|
|
174
|
+
* `alwaysShowSubtitles`, so the next media in it starts with them on too.
|
|
175
|
+
*/
|
|
176
|
+
onAlwaysShowSubtitlesChange?: (always: boolean) => void
|
|
172
177
|
}
|
|
173
178
|
|
|
174
179
|
/**
|
|
@@ -254,8 +259,8 @@ export type MediaPlayerLocalOptions =
|
|
|
254
259
|
|
|
255
260
|
/**
|
|
256
261
|
* The language a file starts its audio in, as `onPreferredAudioLanguageChange` reported it or as any tag or name
|
|
257
|
-
* (`ja`, `jpn`, `Japanese`).
|
|
258
|
-
* track the viewer picks wins for that file. Read when a file starts, so a change applies from the next one.
|
|
262
|
+
* (`ja`, `jpn`, `Japanese`). Only a full track counts, never a commentary or an audio description, and a file with
|
|
263
|
+
* none plays its original. A track the viewer picks wins for that file. Read when a file starts, so a change applies from the next one.
|
|
259
264
|
*/
|
|
260
265
|
preferredAudioLanguage?: string
|
|
261
266
|
/**
|
|
@@ -264,6 +269,17 @@ export type MediaPlayerLocalOptions =
|
|
|
264
269
|
* language starts on the track titled as it is.
|
|
265
270
|
*/
|
|
266
271
|
preferredSubtitleLanguage?: string | null
|
|
272
|
+
/**
|
|
273
|
+
* The language the media was made in, as its source knows it (`ja` for anime): a file with no full track in
|
|
274
|
+
* `preferredAudioLanguage` plays its full track in this one, else its default, its first track. Read as the
|
|
275
|
+
* preferences are.
|
|
276
|
+
*/
|
|
277
|
+
originalLanguage?: string
|
|
278
|
+
/**
|
|
279
|
+
* False starts a file with subtitles off when its audio plays in `preferredSubtitleLanguage`, as it does when the
|
|
280
|
+
* viewer's own language is both. True, the default, starts them as `preferredSubtitleLanguage` says.
|
|
281
|
+
*/
|
|
282
|
+
alwaysShowSubtitles?: boolean
|
|
267
283
|
}
|
|
268
284
|
|
|
269
285
|
/**
|
|
@@ -528,8 +544,8 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
|
|
|
528
544
|
const audio = remote?.audioTracks?.selection
|
|
529
545
|
// `select`'s promise reaches the menu, which is the only place that can hold the popover open, keep the tick off an
|
|
530
546
|
// unfinished switch, and show a failure, and a promise nothing awaits is an unhandled rejection.
|
|
531
|
-
const
|
|
532
|
-
|
|
547
|
+
const latest = useRef({ options, audio })
|
|
548
|
+
latest.current = { options, audio }
|
|
533
549
|
useEffect(() => {
|
|
534
550
|
if (!subtitles) return
|
|
535
551
|
setSourceState({
|
|
@@ -541,7 +557,10 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
|
|
|
541
557
|
const wasOff = subtitles.selectedId === null
|
|
542
558
|
return afterSwitch(subtitles.select(picked), () => {
|
|
543
559
|
const language = picked === null ? null : languageOf(track) ?? (wasOff ? track?.title : undefined)
|
|
544
|
-
|
|
560
|
+
const now = latest.current
|
|
561
|
+
if (language !== undefined) now.options.onPreferredSubtitleLanguageChange?.(language)
|
|
562
|
+
const playing = now.audio && trackOf(now.audio, now.audio.selectedId ?? '')
|
|
563
|
+
if (language && playsIn(playing, language)) now.options.onAlwaysShowSubtitlesChange?.(true)
|
|
545
564
|
})
|
|
546
565
|
},
|
|
547
566
|
subtitleOffLabel: subtitles.offLabel,
|
|
@@ -555,7 +574,7 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
|
|
|
555
574
|
selectedAudioTrack: audio.selectedId ?? undefined,
|
|
556
575
|
selectAudioTrack: (id) => afterSwitch(audio.select(String(id)), () => {
|
|
557
576
|
const language = languageOf(trackOf(audio, String(id)))
|
|
558
|
-
if (language !== undefined)
|
|
577
|
+
if (language !== undefined) latest.current.options.onPreferredAudioLanguageChange?.(language)
|
|
559
578
|
}),
|
|
560
579
|
})
|
|
561
580
|
}, [setSourceState, audio])
|