Add Play Default Audio Track setting.

This commit is contained in:
Jimi 2023-05-06 14:54:33 -06:00
parent 1c33a96439
commit 650a02f686
2 changed files with 30 additions and 16 deletions

View File

@ -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

View File

@ -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