Skip to content

Commit 80937cc

Browse files
improve audio track selection (#100)
1 parent ebc4239 commit 80937cc

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

components/details/ItemDetails.bs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,16 @@ sub onAudioStreamIndexChanged()
17841784
m.top.selectedAudioStreamIndex = m.audioSelector.audioStreamIndex
17851785
m.global.queueManager.callFunc("setPreferredAudioTrackIndex", m.audioSelector.audioStreamIndex)
17861786
m.global.queueManager.callFunc("setPreferredAudioTrackName", m.audioSelector.audioStreamName)
1787+
1788+
if isValid(m.top.itemContent)
1789+
m.top.itemContent.selectedAudioStreamIndex = m.top.selectedAudioStreamIndex
1790+
end if
1791+
1792+
if isValid(m.trackData.audios)
1793+
for each track in m.trackData.audios
1794+
track.Selected = (track.StreamIndex = m.top.selectedAudioStreamIndex)
1795+
end for
1796+
end if
17871797
end if
17881798
end sub
17891799

components/manager/ViewCreator.bs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,25 @@ sub CreateVideoPlayerView()
5353
m.global.audioPlayer.control = VideoControl.STOP
5454
end if
5555

56+
currentItem = m.global.queueManager.callFunc("getCurrentItem")
57+
5658
' If the user has set a preferred audio track index, use it
5759
preferredAudioTrackIndex = m.global.queueManager.callFunc("getPreferredAudioTrackIndex")
5860
if preferredAudioTrackIndex < 0 then preferredAudioTrackIndex = 0
5961

60-
m.global.queueManager.callFunc("setSelectedAudioStreamIndex", preferredAudioTrackIndex)
62+
selectedAudioIndex = preferredAudioTrackIndex
63+
if isValid(currentItem.selectedAudioStreamIndex) and currentItem.selectedAudioStreamIndex >= 0
64+
selectedAudioIndex = currentItem.selectedAudioStreamIndex
65+
end if
66+
67+
m.global.queueManager.callFunc("setSelectedAudioStreamIndex", selectedAudioIndex)
6168

6269
m.view = CreateObject("roSGNode", "VideoPlayerView")
6370
m.view.observeField("state", "onStateChange")
6471
m.view.observeField("selectPlaybackInfoPressed", "onSelectPlaybackInfoPressed")
6572
m.view.observeField("selectSubtitlePressed", "onSelectSubtitlePressed")
6673
m.view.observeField("selectAudioPressed", "onSelectAudioPressed")
6774

68-
currentItem = m.global.queueManager.callFunc("getCurrentItem")
6975
mediaSourceId = currentItem.mediaSourceId
7076

7177
if not isValid(mediaSourceId) or mediaSourceId = ""
@@ -97,6 +103,14 @@ sub onSelectAudioPressed()
97103

98104
preferredAudioTrackName = m.global.queueManager.callFunc("getPreferredAudioTrackName")
99105

106+
currentItem = m.global.queueManager.callFunc("getCurrentItem")
107+
selectedAudioIndex = m.view.audioIndex
108+
if not isValid(selectedAudioIndex) or selectedAudioIndex < 0
109+
if isValid(currentItem.selectedAudioStreamIndex)
110+
selectedAudioIndex = currentItem.selectedAudioStreamIndex
111+
end if
112+
end if
113+
100114
audioTracks = []
101115

102116
for each item in m.view.fullAudioData
@@ -108,7 +122,7 @@ sub onSelectAudioPressed()
108122
}
109123

110124
if isStringEqual(preferredAudioTrackName, string.EMPTY)
111-
if m.view.audioIndex = item.Index
125+
if selectedAudioIndex = item.Index
112126
audioTrack.Selected = true
113127
end if
114128
else

components/movies/AudioSelector.bs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ sub audioTracksSet()
2828
selectedAudioIndex = 0
2929

3030
for each audio in m.top.audioTracks
31-
entry = audioContent.CreateChild("ContentNode")
31+
entry = audioContent.CreateChild("AudioTrackListData")
3232
entry.title = audio.Title
3333
entry.description = audio.Title
34-
entry.StreamIndex = audio.StreamIndex
34+
entry.streamName = audio.RokuTrackName
35+
entry.streamIndex = audio.StreamIndex
3536
if isValid(audio.Selected) and audio.Selected
3637
selectedAudioIndex = index
3738
entry.selected = true
@@ -49,8 +50,8 @@ end sub
4950
sub onAudioItemSelected()
5051
selectedItem = m.audioMenu.content.getChild(m.audioMenu.itemSelected)
5152
if isValid(selectedItem)
52-
m.top.audioStreamIndex = selectedItem.StreamIndex
53-
m.top.audioStreamName = selectedItem.title
53+
m.top.audioStreamIndex = selectedItem.streamIndex
54+
m.top.audioStreamName = selectedItem.streamName
5455
m.top.visible = false
5556
end if
5657
end sub

0 commit comments

Comments
 (0)