From 650a02f686af07df6f5f5cb53950969dce058649 Mon Sep 17 00:00:00 2001 From: Jimi Date: Sat, 6 May 2023 14:54:33 -0600 Subject: [PATCH] Add Play Default Audio Track setting. --- source/Main.brs | 28 ++++++++++++++++------------ source/api/userauth.brs | 18 ++++++++++++++---- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/source/Main.brs b/source/Main.brs index a9376e18..ad488776 100644 --- a/source/Main.brs +++ b/source/Main.brs @@ -122,12 +122,9 @@ sub Main (args as dynamic) as void if itemNode.type = "Episode" or itemNode.type = "Movie" or itemNode.type = "Video" if itemNode.type = "Episode" and itemNode.selectedAudioStreamIndex <> invalid and itemNode.selectedAudioStreamIndex > 1 video = CreateVideoPlayerGroup(itemNode.id, invalid, itemNode.selectedAudioStreamIndex) - else if get_user_setting("display.playback.AudioLanguagePreference") <> invalid - langPreference = get_user_setting("display.playback.AudioLanguagePreference") - preferredLang = FindPreferredAudioStream(itemNode.json.MediaStreams, langPreference) - video = CreateVideoPlayerGroup(itemNode.id, invalid, preferredLang) else - video = CreateVideoPlayerGroup(itemNode.id) + preferredLang = FindPreferredAudioStream(itemNode.json.MediaStreams) + video = CreateVideoPlayerGroup(itemNode.id, invalid, preferredLang) end if if video <> invalid and video.errorMsg <> "introaborted" sceneManager.callFunc("pushScene", video) @@ -615,14 +612,21 @@ sub Main (args as dynamic) as void end sub -function FindPreferredAudioStream(streams, preferredLanguage) +function FindPreferredAudioStream(streams) + preferredLanguage = get_user_setting("display.playback.AudioLanguagePreference") + playDefault = get_user_setting("display.playback.PlayDefaultAudioTrack") - for i = 0 to streams.Count() - 1 - if streams[i].Type = "Audio" and streams[i].Language = preferredLanguage - return i - end if - end for + if playDefault <> invalid and playDefault = "true" + return 1 + end if - return 0 + if preferredLanguage <> invalid + for i = 0 to streams.Count() - 1 + if streams[i].Type = "Audio" and streams[i].Language = preferredLanguage + return i + end if + end for + end if + return 1 end function diff --git a/source/api/userauth.brs b/source/api/userauth.brs index 578059cd..a65ca15e 100644 --- a/source/api/userauth.brs +++ b/source/api/userauth.brs @@ -150,10 +150,20 @@ sub LoadUserPreferences() ' Get users custom configuration resp = APIRequest("Users/Me") jsonResponse = getJson(resp) - if jsonResponse <> invalid and jsonResponse.Configuration <> invalid and jsonResponse.Configuration["AudioLanguagePreference"] <> invalid - set_user_setting("display.playback.AudioLanguagePreference", jsonResponse.Configuration["AudioLanguagePreference"]) - else - unset_user_setting("display.playback.AudioLanguagePreference") + if jsonResponse <> invalid + if jsonResponse.Configuration <> invalid + if jsonResponse.Configuration["AudioLanguagePreference"] <> invalid + set_user_setting("display.playback.AudioLanguagePreference", jsonResponse.Configuration["AudioLanguagePreference"]) + else + unset_user_setting("display.playback.AudioLanguagePreference") + end if + + if jsonResponse.Configuration["PlayDefaultAudioTrack"] <> invalid + set_user_setting("display.playback.PlayDefaultAudioTrack", jsonResponse.Configuration["PlayDefaultAudioTrack"] ? "true" : "false") + else + unset_user_setting("display.playback.PlayDefaultAudioTrack") + end if + end if end if end sub