From 5b4fb38c850a0e16bfc76c094a675e9b3c25c42f Mon Sep 17 00:00:00 2001 From: Andry Yosua Date: Thu, 14 Sep 2023 13:51:50 +0700 Subject: [PATCH] Allow set subtitle language from url parameter (#2935) * allow set subtitle language from url parameter As user, I want to set subtitles language from url parameters, So i do not need to subtitle language each time i switch instances for now you can set `subtitles=xx` (example: `subtitles=en`) on url parameter to set video subtitle language. full url example: https://piped.video/watch?v=6stlCkUDG_s&subtitles=en i choose query `subtitles` so it's compatible with [invidious url parameter](https://docs.invidious.io/url-parameters/) this is especially useful when you have addons like redirector improvement over https://github.com/TeamPiped/Piped/issues/2669 and https://github.com/TeamPiped/Piped/issues/223 * cleaning code * looks simpler and more self-explaining fix suggested on https://github.com/TeamPiped/Piped/pull/2937#discussion_r1325072807 --- src/components/VideoPlayer.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/VideoPlayer.vue b/src/components/VideoPlayer.vue index f988c905..94063864 100644 --- a/src/components/VideoPlayer.vue +++ b/src/components/VideoPlayer.vue @@ -594,6 +594,16 @@ export default { const autoDisplayCaptions = this.getPreferenceBoolean("autoDisplayCaptions", false); this.$player.setTextTrackVisibility(autoDisplayCaptions); + + const prefSubtitles = this.getPreferenceString("subtitles", ""); + if (prefSubtitles !== "") { + const textTracks = this.$player.getTextTracks(); + const subtitleIdx = textTracks.findIndex(textTrack => textTrack.language == prefSubtitles); + if (subtitleIdx != -1) { + this.$player.setTextTrackVisibility(true); + this.$player.selectTextTrack(textTracks[subtitleIdx]); + } + } }) .catch(e => { console.error(e);