From 9d4be2cb55193e217c451226a1fad5f4e1ed82bb Mon Sep 17 00:00:00 2001 From: Jorrin Date: Mon, 8 Apr 2024 16:32:33 +0200 Subject: [PATCH] Select default audio language based on setting --- src/components/player/display/base.ts | 9 ++++++++- src/stores/player/slices/source.ts | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/player/display/base.ts b/src/components/player/display/base.ts index b1eb616f..ebaa12da 100644 --- a/src/components/player/display/base.ts +++ b/src/components/player/display/base.ts @@ -12,6 +12,7 @@ import { } from "@/components/player/display/displayInterface"; import { handleBuffered } from "@/components/player/utils/handleBuffered"; import { getMediaErrorDetails } from "@/components/player/utils/mediaErrorDetails"; +import { useLanguageStore } from "@/stores/language"; import { LoadableSource, SourceQuality, @@ -83,7 +84,13 @@ export function makeVideoElementDisplayInterface(): DisplayInterface { function reportAudioTracks() { if (!hls) return; - const currentTrack = hls.audioTracks?.[hls.audioTrack ?? 0]; + const currentLanguage = useLanguageStore.getState().language; + const audioTracks = hls.audioTracks; + const languageTrack = audioTracks.find((v) => v.lang === currentLanguage); + if (languageTrack) { + hls.audioTrack = audioTracks.indexOf(languageTrack); + } + const currentTrack = audioTracks?.[hls.audioTrack ?? 0]; if (!currentTrack) return; emit("changedaudiotrack", { id: currentTrack.id.toString(), diff --git a/src/stores/player/slices/source.ts b/src/stores/player/slices/source.ts index eb2ce9e1..5cbfc6db 100644 --- a/src/stores/player/slices/source.ts +++ b/src/stores/player/slices/source.ts @@ -169,6 +169,8 @@ export const createSourceSlice: MakeSlice = (set, get) => ({ s.captionList = captions; s.interface.error = undefined; s.status = playerStatus.PLAYING; + s.audioTracks = []; + s.currentAudioTrack = null; }); const store = get(); store.redisplaySource(startAt);