Merge pull request #1522 from 1hitsong/selectAudio

Add audio track selection to video player OSD
This commit is contained in:
1hitsong 2024-01-27 12:09:45 -05:00 committed by GitHub
commit 5efbc92b05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 104 additions and 1 deletions

View File

@ -175,6 +175,7 @@ sub LoadItems_AddVideoContent(video as object, mediaSourceId as dynamic, audio_s
m.playbackInfo = meta.json m.playbackInfo = meta.json
end if end if
addAudioStreamsToVideo(video)
if meta.live if meta.live
video.transcodeParams = { video.transcodeParams = {
"MediaSourceId": m.playbackInfo.MediaSources[0].Id, "MediaSourceId": m.playbackInfo.MediaSources[0].Id,
@ -355,6 +356,23 @@ sub addVideoContentURL(video, mediaSourceId, audio_stream_idx, fully_external)
end if end if
end sub end sub
' addAudioStreamsToVideo: Add audio stream data to video
'
' @param {dynamic} video component to add fullAudioData to
sub addAudioStreamsToVideo(video)
audioStreams = []
mediaStreams = m.playbackInfo.MediaSources[0].MediaStreams
for i = 0 to mediaStreams.Count() - 1
if LCase(mediaStreams[i].Type) = "audio"
audioStreams.push(mediaStreams[i])
end if
end for
video.fullAudioData = audioStreams
end sub
sub addSubtitlesToVideo(video, meta) sub addSubtitlesToVideo(video, meta)
subtitles = sortSubtitles(meta.id, m.playbackInfo.MediaSources[0].MediaStreams) subtitles = sortSubtitles(meta.id, m.playbackInfo.MediaSources[0].MediaStreams)
safesubs = subtitles["all"] safesubs = subtitles["all"]

View File

@ -109,7 +109,8 @@ sub onContentDataChanged()
m.radioOptions.selectedIndex = i m.radioOptions.selectedIndex = i
end if end if
textLine = cardItem.CreateChild("SimpleLabel") textLine = cardItem.CreateChild("ScrollingLabel")
textLine.maxWidth = "750"
textLine.text = item.track.description textLine.text = item.track.description
cardItem.observeField("selected", "onItemSelected") cardItem.observeField("selected", "onItemSelected")
i++ i++

View File

@ -14,6 +14,7 @@ sub CreateVideoPlayerView()
m.view.observeField("state", "onStateChange") m.view.observeField("state", "onStateChange")
m.view.observeField("selectPlaybackInfoPressed", "onSelectPlaybackInfoPressed") m.view.observeField("selectPlaybackInfoPressed", "onSelectPlaybackInfoPressed")
m.view.observeField("selectSubtitlePressed", "onSelectSubtitlePressed") m.view.observeField("selectSubtitlePressed", "onSelectSubtitlePressed")
m.view.observeField("selectAudioPressed", "onSelectAudioPressed")
mediaSourceId = m.global.queueManager.callFunc("getCurrentItem").mediaSourceId mediaSourceId = m.global.queueManager.callFunc("getCurrentItem").mediaSourceId
@ -32,6 +33,36 @@ end sub
' Event Handlers ' Event Handlers
' ----------------- ' -----------------
' onSelectAudioPressed: Display audio selection dialog
'
sub onSelectAudioPressed()
audioData = {
data: []
}
for each item in m.view.fullAudioData
audioStreamItem = {
"Index": item.Index,
"IsExternal": item.IsExternal,
"Track": {
"description": item.DisplayTitle
},
"Type": "audioselection"
}
if m.view.audioIndex = item.Index
audioStreamItem.selected = true
end if
audioData.data.push(audioStreamItem)
end for
m.global.sceneManager.callFunc("radioDialog", tr("Select Audio"), audioData)
m.global.sceneManager.observeField("returnData", "onSelectionMade")
end sub
' User requested subtitle selection popup ' User requested subtitle selection popup
sub onSelectSubtitlePressed() sub onSelectSubtitlePressed()
' None is always first in the subtitle list ' None is always first in the subtitle list
@ -85,6 +116,25 @@ sub onSelectionMade()
if LCase(m.global.sceneManager.returnData.type) = "subtitleselection" if LCase(m.global.sceneManager.returnData.type) = "subtitleselection"
processSubtitleSelection() processSubtitleSelection()
return
end if
if LCase(m.global.sceneManager.returnData.type) = "audioselection"
processAudioSelection()
return
end if
end sub
' processAudioSelection: Audio track selection handler
'
sub processAudioSelection()
selectedAudioTrack = m.global.sceneManager.returnData
if isValid(selectedAudioTrack)
if isValid(selectedAudioTrack.index)
m.view.audioIndex = selectedAudioTrack.index
end if
end if end if
end sub end sub

View File

@ -8,6 +8,7 @@
<IconButton id="showVideoInfoPopup" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/videoInfo.png" height="65" width="100" /> <IconButton id="showVideoInfoPopup" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/videoInfo.png" height="65" width="100" />
<IconButton id="chapterList" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/numberList.png" height="65" width="100" /> <IconButton id="chapterList" background="#070707" focusBackground="#00a4dc" padding="16" icon="pkg:/images/icons/numberList.png" height="65" width="100" />
<IconButton id="showSubtitleMenu" background="#070707" focusBackground="#00a4dc" padding="0" icon="pkg:/images/icons/subtitle.png" height="65" width="100" /> <IconButton id="showSubtitleMenu" background="#070707" focusBackground="#00a4dc" padding="0" icon="pkg:/images/icons/subtitle.png" height="65" width="100" />
<IconButton id="showAudioMenu" background="#070707" focusBackground="#00a4dc" padding="27" icon="pkg:/images/icons/musicNote.png" height="65" width="100" />
</ButtonGroup> </ButtonGroup>
<ButtonGroup id="videoControls" itemSpacings="[20]" layoutDirection="horiz" horizAlignment="center" translation="[960,875]"> <ButtonGroup id="videoControls" itemSpacings="[20]" layoutDirection="horiz" horizAlignment="center" translation="[960,875]">

View File

@ -32,6 +32,7 @@ sub init()
m.top.observeField("state", "onState") m.top.observeField("state", "onState")
m.top.observeField("content", "onContentChange") m.top.observeField("content", "onContentChange")
m.top.observeField("selectedSubtitle", "onSubtitleChange") m.top.observeField("selectedSubtitle", "onSubtitleChange")
m.top.observeField("audioIndex", "onAudioIndexChange")
' Custom Caption Function ' Custom Caption Function
m.top.observeField("allowCaptions", "onAllowCaptionsChange") m.top.observeField("allowCaptions", "onAllowCaptionsChange")
@ -163,6 +164,12 @@ sub handleShowSubtitleMenuAction()
m.top.selectSubtitlePressed = true m.top.selectSubtitlePressed = true
end sub end sub
' handleShowAudioMenuAction: Handles action to show audio selection menu
'
sub handleShowAudioMenuAction()
m.top.selectAudioPressed = true
end sub
' handleShowVideoInfoPopupAction: Handles action to show video info popup ' handleShowVideoInfoPopupAction: Handles action to show video info popup
' '
sub handleShowVideoInfoPopupAction() sub handleShowVideoInfoPopupAction()
@ -204,6 +211,11 @@ sub onOSDAction()
return return
end if end if
if action = "showaudiomenu"
handleShowAudioMenuAction()
return
end if
if action = "showvideoinfopopup" if action = "showvideoinfopopup"
handleShowVideoInfoPopupAction() handleShowVideoInfoPopupAction()
return return
@ -274,6 +286,24 @@ sub onSubtitleChange()
m.top.control = "stop" m.top.control = "stop"
m.LoadMetaDataTask.selectedSubtitleIndex = m.top.SelectedSubtitle m.LoadMetaDataTask.selectedSubtitleIndex = m.top.SelectedSubtitle
m.LoadMetaDataTask.selectedAudioStreamIndex = m.top.audioIndex
m.LoadMetaDataTask.itemId = m.currentItem.id
m.LoadMetaDataTask.observeField("content", "onVideoContentLoaded")
m.LoadMetaDataTask.control = "RUN"
end sub
' Event handler for when audioIndex changes
sub onAudioIndexChange()
' Skip initial audio index setting
if m.top.position = 0 then return
' Save the current video position
m.global.queueManager.callFunc("setTopStartingPoint", int(m.top.position) * 10000000&)
m.top.control = "stop"
m.LoadMetaDataTask.selectedSubtitleIndex = m.top.SelectedSubtitle
m.LoadMetaDataTask.selectedAudioStreamIndex = m.top.audioIndex
m.LoadMetaDataTask.itemId = m.currentItem.id m.LoadMetaDataTask.itemId = m.currentItem.id
m.LoadMetaDataTask.observeField("content", "onVideoContentLoaded") m.LoadMetaDataTask.observeField("content", "onVideoContentLoaded")
m.LoadMetaDataTask.control = "RUN" m.LoadMetaDataTask.control = "RUN"
@ -328,6 +358,7 @@ sub onVideoContentLoaded()
m.top.container = videoContent[0].container m.top.container = videoContent[0].container
m.top.mediaSourceId = videoContent[0].mediaSourceId m.top.mediaSourceId = videoContent[0].mediaSourceId
m.top.fullSubtitleData = videoContent[0].fullSubtitleData m.top.fullSubtitleData = videoContent[0].fullSubtitleData
m.top.fullAudioData = videoContent[0].fullAudioData
m.top.audioIndex = videoContent[0].audioIndex m.top.audioIndex = videoContent[0].audioIndex
m.top.transcodeParams = videoContent[0].transcodeparams m.top.transcodeParams = videoContent[0].transcodeparams
m.chapters = videoContent[0].chapters m.chapters = videoContent[0].chapters

View File

@ -3,6 +3,7 @@
<interface> <interface>
<field id="backPressed" type="boolean" alwaysNotify="true" /> <field id="backPressed" type="boolean" alwaysNotify="true" />
<field id="selectSubtitlePressed" type="boolean" alwaysNotify="true" /> <field id="selectSubtitlePressed" type="boolean" alwaysNotify="true" />
<field id="selectAudioPressed" type="boolean" alwaysNotify="true" />
<field id="selectPlaybackInfoPressed" type="boolean" alwaysNotify="true" /> <field id="selectPlaybackInfoPressed" type="boolean" alwaysNotify="true" />
<field id="PlaySessionId" type="string" /> <field id="PlaySessionId" type="string" />
<field id="Subtitles" type="array" /> <field id="Subtitles" type="array" />
@ -23,6 +24,7 @@
<field id="videoId" type="string" /> <field id="videoId" type="string" />
<field id="mediaSourceId" type="string" /> <field id="mediaSourceId" type="string" />
<field id="fullSubtitleData" type="array" /> <field id="fullSubtitleData" type="array" />
<field id="fullAudioData" type="array" />
<field id="audioIndex" type="integer" /> <field id="audioIndex" type="integer" />
<field id="allowCaptions" type="boolean" value="false" /> <field id="allowCaptions" type="boolean" value="false" />
</interface> </interface>

BIN
images/icons/musicNote.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB