jf-roku/source/Main.brs

648 lines
30 KiB
Plaintext
Raw Normal View History

2021-07-09 20:08:32 +00:00
sub Main (args as dynamic) as void
' The main function that runs when the application is launched.
m.screen = CreateObject("roSGScreen")
' Set global constants
setConstants()
2022-06-03 01:29:07 +00:00
' Write screen tracker for screensaver
WriteAsciiFile("tmp:/scene.temp", "")
MoveFile("tmp:/scene.temp", "tmp:/scene")
2021-07-09 20:08:32 +00:00
m.port = CreateObject("roMessagePort")
m.screen.setMessagePort(m.port)
' Set any initial Global Variables
m.global = m.screen.getGlobalNode()
SaveAppToGlobal()
SaveDeviceToGlobal()
m.scene = m.screen.CreateScene("JFScene")
m.screen.show() ' vscode_rale_tracker_entry
playstateTask = CreateObject("roSGNode", "PlaystateTask")
playstateTask.id = "playstateTask"
sceneManager = CreateObject("roSGNode", "SceneManager")
2021-07-09 20:08:32 +00:00
m.global.addFields({ app_loaded: false, playstateTask: playstateTask, sceneManager: sceneManager })
2022-11-29 22:05:46 +00:00
m.global.addFields({ queueManager: CreateObject("roSGNode", "QueueManager") })
m.global.addFields({ audioPlayer: CreateObject("roSGNode", "AudioPlayer") })
2021-07-09 20:08:32 +00:00
app_start:
' First thing to do is validate the ability to use the API
if not LoginFlow() then return
' remove previous scenes from the stack
sceneManager.callFunc("clearScenes")
' save user config
m.global.addFields({ userConfig: m.user.configuration })
2021-07-09 20:08:32 +00:00
' load home page
sceneManager.currentUser = m.user.Name
2021-07-09 20:08:32 +00:00
group = CreateHomeGroup()
group.callFunc("loadLibraries")
sceneManager.callFunc("pushScene", group)
2021-07-09 20:08:32 +00:00
m.scene.observeField("exit", m.port)
2021-07-09 20:08:32 +00:00
' Downloads and stores a fallback font to tmp:/
configEncoding = api_API().system.getconfigurationbyname("encoding")
if isValid(configEncoding) and isValid(configEncoding.EnableFallbackFont)
if configEncoding.EnableFallbackFont
re = CreateObject("roRegex", "Name.:.(.*?).,.Size", "s")
filename = APIRequest("FallbackFont/Fonts").GetToString()
if isValid(filename)
filename = re.match(filename)
if isValid(filename) and filename.count() > 0
filename = filename[1]
APIRequest("FallbackFont/Fonts/" + filename).gettofile("tmp:/font")
end if
end if
end if
end if
' Only show the Whats New popup the first time a user runs a new client version.
2023-03-27 16:40:13 +00:00
if m.global.app.version <> get_setting("LastRunVersion")
' Ensure the user hasn't disabled Whats New popups
if get_user_setting("load.allowwhatsnew") = "true"
2023-03-27 16:40:13 +00:00
set_setting("LastRunVersion", m.global.app.version)
dialog = createObject("roSGNode", "WhatsNewDialog")
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", m.port)
end if
end if
2021-07-09 20:08:32 +00:00
' Handle input messages
input = CreateObject("roInput")
input.SetMessagePort(m.port)
device = CreateObject("roDeviceInfo")
device.setMessagePort(m.port)
device.EnableScreensaverExitedEvent(true)
device.EnableAppFocusEvent(false)
device.EnableAudioGuideChangedEvent(true)
2021-07-09 20:08:32 +00:00
' Check if we were sent content to play with the startup command (Deep Link)
2022-12-29 00:51:31 +00:00
if isValidAndNotEmpty(args.mediaType) and isValidAndNotEmpty(args.contentId)
2021-07-09 20:08:32 +00:00
video = CreateVideoPlayerGroup(args.contentId)
2022-12-23 17:08:26 +00:00
if isValid(video) and video.errorMsg <> "introaborted"
sceneManager.callFunc("pushScene", video)
2020-11-30 07:46:20 +00:00
else
2021-07-09 20:08:32 +00:00
dialog = createObject("roSGNode", "Dialog")
dialog.id = "OKDialog"
dialog.title = tr("Not found")
dialog.message = tr("The requested content does not exist on the server")
dialog.buttons = [tr("OK")]
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", m.port)
2020-11-30 07:46:20 +00:00
end if
2021-07-09 20:08:32 +00:00
end if
' This is the core logic loop. Mostly for transitioning between scenes
' This now only references m. fields so could be placed anywhere, in theory
' "group" is always "whats on the screen"
' m.scene's children is the "previous view" stack
while true
msg = wait(0, m.port)
if type(msg) = "roSGScreenEvent" and msg.isScreenClosed()
print "CLOSING SCREEN"
return
else if isNodeEvent(msg, "exit")
return
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "closeSidePanel")
group = sceneManager.callFunc("getActiveScene")
2021-07-09 20:08:32 +00:00
if group.lastFocus <> invalid
group.lastFocus.setFocus(true)
else
group.setFocus(true)
end if
else if isNodeEvent(msg, "quickPlayNode")
2022-12-10 19:27:49 +00:00
group = sceneManager.callFunc("getActiveScene")
2021-07-09 20:08:32 +00:00
reportingNode = msg.getRoSGNode()
itemNode = reportingNode.quickPlayNode
if itemNode = invalid or itemNode.id = "" then return
if itemNode.type = "Episode" or itemNode.type = "Movie" or itemNode.type = "Video"
if itemNode.type = "Episode" and itemNode.selectedAudioStreamIndex <> invalid and itemNode.selectedAudioStreamIndex > 0
video = CreateVideoPlayerGroup(itemNode.id, invalid, itemNode.selectedAudioStreamIndex)
else
2023-05-06 20:54:33 +00:00
preferredLang = FindPreferredAudioStream(itemNode.json.MediaStreams)
video = CreateVideoPlayerGroup(itemNode.id, invalid, preferredLang)
end if
2022-07-09 08:28:15 +00:00
if video <> invalid and video.errorMsg <> "introaborted"
sceneManager.callFunc("pushScene", video)
2021-07-09 20:08:32 +00:00
end if
if LCase(group.subtype()) = "tvepisodes"
if isValid(group.lastFocus)
group.lastFocus.setFocus(true)
end if
end if
2021-07-09 20:08:32 +00:00
end if
else if isNodeEvent(msg, "selectedItem")
' If you select a library from ANYWHERE, follow this flow
selectedItem = msg.getData()
2022-09-24 00:16:52 +00:00
m.selectedItemType = selectedItem.type
2022-12-30 16:11:19 +00:00
if selectedItem.type = "CollectionFolder" or selectedItem.type = "BoxSet"
2022-09-24 00:16:52 +00:00
if selectedItem.collectionType = "movies"
group = CreateMovieLibraryView(selectedItem)
2022-12-10 05:06:56 +00:00
else if selectedItem.collectionType = "music"
group = CreateMusicLibraryView(selectedItem)
2022-09-24 00:16:52 +00:00
else
group = CreateItemGrid(selectedItem)
end if
sceneManager.callFunc("pushScene", group)
else if selectedItem.type = "Folder" and selectedItem.json.type = "Genre"
2022-12-30 16:11:19 +00:00
' User clicked on a genre folder
2023-01-27 00:39:25 +00:00
if selectedItem.json.MovieCount > 0
2022-12-30 16:11:19 +00:00
group = CreateMovieLibraryView(selectedItem)
else
group = CreateItemGrid(selectedItem)
end if
sceneManager.callFunc("pushScene", group)
2022-12-10 05:06:56 +00:00
else if selectedItem.type = "Folder" and selectedItem.json.type = "MusicGenre"
group = CreateMusicLibraryView(selectedItem)
2022-09-24 00:16:52 +00:00
sceneManager.callFunc("pushScene", group)
else if selectedItem.type = "UserView" or selectedItem.type = "Folder" or selectedItem.type = "Channel" or selectedItem.type = "Boxset"
2021-07-09 20:08:32 +00:00
group = CreateItemGrid(selectedItem)
sceneManager.callFunc("pushScene", group)
2021-07-09 20:08:32 +00:00
else if selectedItem.type = "Episode"
' play episode
' todo: create an episode page to link here
video_id = selectedItem.id
2022-04-30 13:02:03 +00:00
if selectedItem.selectedAudioStreamIndex <> invalid and selectedItem.selectedAudioStreamIndex > 1
video = CreateVideoPlayerGroup(video_id, invalid, selectedItem.selectedAudioStreamIndex)
else
2023-05-06 21:35:16 +00:00
preferredLang = FindPreferredAudioStream(invalid, video_id)
video = CreateVideoPlayerGroup(video_id, invalid, preferredLang)
end if
2022-07-09 08:28:15 +00:00
if video <> invalid and video.errorMsg <> "introaborted"
sceneManager.callFunc("pushScene", video)
2021-07-09 20:08:32 +00:00
end if
else if selectedItem.type = "Series"
group = CreateSeriesDetailsGroup(selectedItem.json)
2022-11-05 00:37:54 +00:00
else if selectedItem.type = "Season"
group = CreateSeasonDetailsGroupByID(selectedItem.json.SeriesId, selectedItem.id)
2021-07-09 20:08:32 +00:00
else if selectedItem.type = "Movie"
' open movie detail page
group = CreateMovieDetailsGroup(selectedItem)
2022-03-13 08:46:03 +00:00
else if selectedItem.type = "Person"
CreatePersonView(selectedItem)
2021-12-18 06:03:33 +00:00
else if selectedItem.type = "TvChannel" or selectedItem.type = "Video" or selectedItem.type = "Program"
2021-07-09 20:08:32 +00:00
' play channel feed
video_id = selectedItem.id
' Show Channel Loading spinner
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Loading Channel Data")
m.scene.dialog = dialog
if LCase(selectedItem.subtype()) = "extrasdata"
video = CreateVideoPlayerGroup(video_id, invalid, 1, false, true, false)
else
video = CreateVideoPlayerGroup(video_id)
end if
2021-07-09 20:08:32 +00:00
dialog.close = true
2022-07-09 08:28:15 +00:00
if video <> invalid and video.errorMsg <> "introaborted"
sceneManager.callFunc("pushScene", video)
2021-07-09 20:08:32 +00:00
else
dialog = createObject("roSGNode", "Dialog")
dialog.id = "OKDialog"
dialog.title = tr("Error loading Channel Data")
dialog.message = tr("Unable to load Channel Data from the server")
dialog.buttons = [tr("OK")]
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", m.port)
end if
2022-02-06 15:37:02 +00:00
else if selectedItem.type = "Photo"
2022-02-06 22:37:40 +00:00
' Nothing to do here, handled in ItemGrid
2022-05-14 02:35:50 +00:00
else if selectedItem.type = "MusicArtist"
2022-07-19 00:42:22 +00:00
group = CreateArtistView(selectedItem.json)
2022-10-02 18:23:42 +00:00
if not isValid(group)
message_dialog(tr("Unable to find any albums or songs belonging to this artist"))
end if
else if selectedItem.type = "MusicAlbum"
2022-07-19 00:42:22 +00:00
group = CreateAlbumView(selectedItem.json)
else if selectedItem.type = "Playlist"
group = CreatePlaylistView(selectedItem.json)
2022-05-15 02:30:29 +00:00
else if selectedItem.type = "Audio"
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("push", selectedItem.json)
m.global.queueManager.callFunc("playQueue")
2021-07-09 20:08:32 +00:00
else
' TODO - switch on more node types
message_dialog("This type is not yet supported: " + selectedItem.type + ".")
2021-07-09 20:08:32 +00:00
end if
else if isNodeEvent(msg, "movieSelected")
' If you select a movie from ANYWHERE, follow this flow
node = getMsgPicker(msg, "picker")
group = CreateMovieDetailsGroup(node)
else if isNodeEvent(msg, "seriesSelected")
' If you select a TV Series from ANYWHERE, follow this flow
node = getMsgPicker(msg, "picker")
group = CreateSeriesDetailsGroup(node)
else if isNodeEvent(msg, "seasonSelected")
' If you select a TV Season from ANYWHERE, follow this flow
ptr = msg.getData()
' ptr is for [row, col] of selected item... but we only have 1 row
series = msg.getRoSGNode()
if isValid(ptr) and ptr.count() >= 2 and isValid(ptr[1]) and isValid(series) and isValid(series.seasonData) and isValid(series.seasonData.items)
node = series.seasonData.items[ptr[1]]
group = CreateSeasonDetailsGroup(series.itemContent, node)
end if
2022-05-14 03:46:05 +00:00
else if isNodeEvent(msg, "musicAlbumSelected")
' If you select a Music Album from ANYWHERE, follow this flow
ptr = msg.getData()
albums = msg.getRoSGNode()
2022-07-19 02:28:06 +00:00
node = albums.musicArtistAlbumData.items[ptr]
2022-07-19 00:42:22 +00:00
group = CreateAlbumView(node)
2022-09-27 01:26:17 +00:00
else if isNodeEvent(msg, "appearsOnSelected")
' If you select a Music Album from ANYWHERE, follow this flow
ptr = msg.getData()
albums = msg.getRoSGNode()
node = albums.musicArtistAppearsOnData.items[ptr]
group = CreateAlbumView(node)
2022-05-21 20:45:01 +00:00
else if isNodeEvent(msg, "playSong")
' User has selected audio they want us to play
2022-05-15 02:30:29 +00:00
selectedIndex = msg.getData()
2022-05-21 20:45:01 +00:00
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
m.global.queueManager.callFunc("push", screenContent.albumData.items[selectedIndex])
m.global.queueManager.callFunc("playQueue")
else if isNodeEvent(msg, "playItem")
' User has selected audio they want us to play
selectedIndex = msg.getData()
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("push", screenContent.albumData.items[selectedIndex])
m.global.queueManager.callFunc("playQueue")
2022-05-15 19:10:21 +00:00
else if isNodeEvent(msg, "playAllSelected")
2022-05-21 20:45:01 +00:00
' User has selected playlist of of audio they want us to play
screenContent = msg.getRoSGNode()
2022-05-22 21:32:03 +00:00
m.spinner = screenContent.findNode("spinner")
m.spinner.visible = true
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", screenContent.albumData.items)
m.global.queueManager.callFunc("playQueue")
2022-07-19 02:28:06 +00:00
else if isNodeEvent(msg, "playArtistSelected")
' User has selected playlist of of audio they want us to play
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", CreateArtistMix(screenContent.pageContent.id).Items)
m.global.queueManager.callFunc("playQueue")
2022-06-08 13:08:05 +00:00
else if isNodeEvent(msg, "instantMixSelected")
' User has selected instant mix
' User has selected playlist of of audio they want us to play
screenContent = msg.getRoSGNode()
m.spinner = screenContent.findNode("spinner")
2022-07-19 02:28:06 +00:00
if isValid(m.spinner)
m.spinner.visible = true
end if
2022-11-29 22:05:46 +00:00
viewHandled = false
' Create instant mix based on selected album
2022-07-19 02:28:06 +00:00
if isValid(screenContent.albumData)
if isValid(screenContent.albumData.items)
if screenContent.albumData.items.count() > 0
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", CreateInstantMix(screenContent.albumData.items[0].id).Items)
m.global.queueManager.callFunc("playQueue")
viewHandled = true
end if
end if
2022-07-19 02:28:06 +00:00
end if
2022-11-29 22:05:46 +00:00
if not viewHandled
' Create instant mix based on selected artist
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("set", CreateInstantMix(screenContent.pageContent.id).Items)
m.global.queueManager.callFunc("playQueue")
end if
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "episodeSelected")
' If you select a TV Episode from ANYWHERE, follow this flow
m.selectedItemType = "Episode"
2021-07-09 20:08:32 +00:00
node = getMsgPicker(msg, "picker")
video_id = node.id
2022-04-30 13:02:03 +00:00
if node.selectedAudioStreamIndex <> invalid and node.selectedAudioStreamIndex > 1
video = CreateVideoPlayerGroup(video_id, invalid, node.selectedAudioStreamIndex)
else
video = CreateVideoPlayerGroup(video_id)
end if
2022-07-09 08:28:15 +00:00
if video <> invalid and video.errorMsg <> "introaborted"
sceneManager.callFunc("pushScene", video)
2021-07-09 20:08:32 +00:00
end if
else if isNodeEvent(msg, "search_value")
query = msg.getRoSGNode().search_value
group.findNode("SearchBox").visible = false
options = group.findNode("SearchSelect")
options.visible = true
options.setFocus(true)
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Loading Search Data")
m.scene.dialog = dialog
results = SearchMedia(query)
dialog.close = true
options.itemData = results
options.query = query
else if isNodeEvent(msg, "itemSelected")
' Search item selected
node = getMsgPicker(msg)
' TODO - swap this based on target.mediatype
' types: [ Series (Show), Episode, Movie, Audio, Person, Studio, MusicArtist ]
m.selectedItemType = node.type
2021-07-09 20:08:32 +00:00
if node.type = "Series"
group = CreateSeriesDetailsGroup(node)
else if node.type = "Movie"
2021-07-09 20:08:32 +00:00
group = CreateMovieDetailsGroup(node)
else if node.type = "MusicArtist"
group = CreateArtistView(node.json)
else if node.type = "MusicAlbum"
group = CreateAlbumView(node.json)
else if node.type = "Audio"
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("push", node.json)
m.global.queueManager.callFunc("playQueue")
else if node.type = "Person"
group = CreatePersonView(node)
else if node.type = "TvChannel"
group = CreateVideoPlayerGroup(node.id)
sceneManager.callFunc("pushScene", group)
else if node.type = "Episode"
group = CreateVideoPlayerGroup(node.id)
sceneManager.callFunc("pushScene", group)
else if node.type = "Audio"
selectedIndex = msg.getData()
screenContent = msg.getRoSGNode()
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("clear")
2023-04-08 17:48:57 +00:00
m.global.queueManager.callFunc("resetShuffle")
2022-11-29 22:05:46 +00:00
m.global.queueManager.callFunc("push", screenContent.albumData.items[node.id])
m.global.queueManager.callFunc("playQueue")
else
' TODO - switch on more node types
message_dialog("This type is not yet supported: " + node.type + ".")
2021-04-14 07:03:15 +00:00
end if
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "buttonSelected")
' If a button is selected, we have some determining to do
btn = getButton(msg)
group = sceneManager.callFunc("getActiveScene")
if isValid(btn) and btn.id = "play-button"
2022-03-13 00:36:11 +00:00
' Check if a specific Audio Stream was selected
2021-07-09 20:08:32 +00:00
audio_stream_idx = 1
if isValid(group) and isValid(group.selectedAudioStreamIndex)
2021-07-09 20:08:32 +00:00
audio_stream_idx = group.selectedAudioStreamIndex
end if
2022-03-13 00:36:11 +00:00
' Check to see if a specific video "version" was selected
2022-03-13 14:22:55 +00:00
mediaSourceId = invalid
if isValid(group) and isValid(group.selectedVideoStreamId)
2022-03-13 14:22:55 +00:00
mediaSourceId = group.selectedVideoStreamId
2022-03-13 00:36:11 +00:00
end if
2022-03-13 14:22:55 +00:00
video_id = group.id
video = CreateVideoPlayerGroup(video_id, mediaSourceId, audio_stream_idx)
if isValid(video) and video.errorMsg <> "introaborted"
sceneManager.callFunc("pushScene", video)
2021-07-09 20:08:32 +00:00
end if
if isValid(group) and isValid(group.lastFocus) and isValid(group.lastFocus.id) and group.lastFocus.id = "main_group"
2022-12-09 23:27:16 +00:00
buttons = group.findNode("buttons")
if isValid(buttons)
group.lastFocus = group.findNode("buttons")
2022-12-09 23:27:16 +00:00
end if
end if
if isValid(group) and isValid(group.lastFocus)
2022-09-03 07:31:15 +00:00
group.lastFocus.setFocus(true)
end if
2022-12-09 23:27:16 +00:00
2022-09-03 07:31:15 +00:00
else if btn <> invalid and btn.id = "trailer-button"
dialog = createObject("roSGNode", "ProgressDialog")
dialog.title = tr("Loading trailer")
m.scene.dialog = dialog
2022-09-03 07:31:15 +00:00
audio_stream_idx = 1
mediaSourceId = invalid
video_id = group.id
trailerData = api_API().users.getlocaltrailers(get_setting("active_user"), group.id)
video = invalid
2022-09-03 07:31:15 +00:00
if isValid(trailerData) and isValid(trailerData[0]) and isValid(trailerData[0].id)
video_id = trailerData[0].id
video = CreateVideoPlayerGroup(video_id, mediaSourceId, audio_stream_idx, false, false)
end if
2022-09-03 07:31:15 +00:00
if isValid(video) and video.errorMsg <> "introaborted"
2022-09-03 07:31:15 +00:00
sceneManager.callFunc("pushScene", video)
dialog.close = true
2022-09-03 07:31:15 +00:00
end if
if isValid(group) and isValid(group.lastFocus)
group.lastFocus.setFocus(true)
end if
2021-07-09 20:08:32 +00:00
else if btn <> invalid and btn.id = "watched-button"
movie = group.itemContent
if isValid(movie) and isValid(movie.watched) and isValid(movie.id)
if movie.watched
UnmarkItemWatched(movie.id)
else
MarkItemWatched(movie.id)
end if
movie.watched = not movie.watched
2021-07-09 20:08:32 +00:00
end if
else if btn <> invalid and btn.id = "favorite-button"
movie = group.itemContent
if movie.favorite
UnmarkItemFavorite(movie.id)
else
MarkItemFavorite(movie.id)
end if
movie.favorite = not movie.favorite
else
' If there are no other button matches, check if this is a simple "OK" Dialog & Close if so
dialog = msg.getRoSGNode()
if dialog.id = "OKDialog"
dialog.unobserveField("buttonSelected")
dialog.close = true
end if
end if
else if isNodeEvent(msg, "optionSelected")
button = msg.getRoSGNode()
group = sceneManager.callFunc("getActiveScene")
if button.id = "goto_search" and isValid(group)
2021-07-09 20:08:32 +00:00
' Exit out of the side panel
panel = group.findNode("options")
2021-07-09 20:08:32 +00:00
panel.visible = false
if isValid(group.lastFocus)
2021-07-09 20:08:32 +00:00
group.lastFocus.setFocus(true)
else
group.setFocus(true)
end if
group = CreateSearchPage()
sceneManager.callFunc("pushScene", group)
group.findNode("SearchBox").findNode("search_Key").setFocus(true)
group.findNode("SearchBox").findNode("search_Key").active = true
2021-07-09 20:08:32 +00:00
else if button.id = "change_server"
unset_setting("server")
unset_setting("port")
2021-12-30 01:00:13 +00:00
SignOut(false)
sceneManager.callFunc("clearScenes")
2021-07-09 20:08:32 +00:00
goto app_start
else if button.id = "sign_out"
SignOut()
sceneManager.callFunc("clearScenes")
2021-07-09 20:08:32 +00:00
goto app_start
2022-05-01 10:51:28 +00:00
else if button.id = "settings"
' Exit out of the side panel
panel = group.findNode("options")
panel.visible = false
if isValid(group) and isValid(group.lastFocus)
2022-05-01 10:51:28 +00:00
group.lastFocus.setFocus(true)
else
group.setFocus(true)
end if
sceneManager.callFunc("settings")
2021-07-09 20:08:32 +00:00
end if
else if isNodeEvent(msg, "selectSubtitlePressed")
node = m.scene.focusedChild
2021-12-23 07:56:57 +00:00
if node.focusedChild <> invalid and node.focusedChild.isSubType("JFVideo")
2021-07-09 20:08:32 +00:00
trackSelected = selectSubtitleTrack(node.Subtitles, node.SelectedSubtitle)
if trackSelected <> invalid and trackSelected <> -2
changeSubtitleDuringPlayback(trackSelected)
end if
end if
2022-09-06 04:38:37 +00:00
else if isNodeEvent(msg, "selectPlaybackInfoPressed")
node = m.scene.focusedChild
if node.focusedChild <> invalid and node.focusedChild.isSubType("JFVideo")
info = GetPlaybackInfo()
show_dialog(tr("Playback Information"), info)
end if
2021-07-09 20:08:32 +00:00
else if isNodeEvent(msg, "state")
node = msg.getRoSGNode()
if isValid(node) and isValid(node.state)
if m.selectedItemType = "TvChannel" and node.state = "finished"
video = CreateVideoPlayerGroup(node.id)
m.global.sceneManager.callFunc("pushScene", video)
m.global.sceneManager.callFunc("deleteSceneAtIndex", 2)
else if node.state = "finished"
node.control = "stop"
' If node allows retrying using Transcode Url, give that shot
if isValid(node.retryWithTranscoding) and node.retryWithTranscoding
retryVideo = CreateVideoPlayerGroup(node.Id, invalid, node.audioIndex, true, false)
m.global.sceneManager.callFunc("popScene")
if isValid(retryVideo)
m.global.sceneManager.callFunc("pushScene", retryVideo)
end if
else if not isValid(node.showID)
2023-01-31 01:02:00 +00:00
sceneManager.callFunc("popScene")
else
if video.errorMsg = ""
autoPlayNextEpisode(node.id, node.showID)
else
sceneManager.callFunc("popScene")
end if
2023-01-31 01:02:00 +00:00
end if
2021-07-09 20:08:32 +00:00
end if
end if
else if type(msg) = "roDeviceInfoEvent"
event = msg.GetInfo()
2021-07-09 20:08:32 +00:00
if event.exitedScreensaver = true
sceneManager.callFunc("resetTime")
group = sceneManager.callFunc("getActiveScene")
if isValid(group) and isValid(group.subtype())
' refresh the current view
if group.subtype() = "Home"
currentTime = CreateObject("roDateTime").AsSeconds()
group.timeLastRefresh = currentTime
group.callFunc("refresh")
end if
' todo: add other screens to be refreshed - movie detail, tv series, episode list etc.
2021-07-09 20:08:32 +00:00
end if
else if event.audioGuideEnabled <> invalid
tmpGlobalDevice = m.global.device
2023-04-21 23:16:19 +00:00
tmpGlobalDevice.AddReplace("isaudioguideenabled", event.audioGuideEnabled)
' update global device array
m.global.setFields({ device: tmpGlobalDevice })
2021-07-09 20:08:32 +00:00
else
print "Unhandled roDeviceInfoEvent:"
print msg.GetInfo()
end if
else if type(msg) = "roInputEvent"
if msg.IsInput()
info = msg.GetInfo()
if info.DoesExist("mediatype") and info.DoesExist("contentid")
video = CreateVideoPlayerGroup(info.contentId)
2022-07-09 08:28:15 +00:00
if video <> invalid and video.errorMsg <> "introaborted"
sceneManager.callFunc("pushScene", video)
2021-07-09 20:08:32 +00:00
else
dialog = createObject("roSGNode", "Dialog")
dialog.id = "OKDialog"
dialog.title = tr("Not found")
dialog.message = tr("The requested content does not exist on the server")
dialog.buttons = [tr("OK")]
m.scene.dialog = dialog
m.scene.dialog.observeField("buttonSelected", m.port)
end if
end if
end if
else
print "Unhandled " type(msg)
print msg
end if
end while
end sub
2023-05-06 20:34:17 +00:00
2023-05-06 21:35:16 +00:00
function FindPreferredAudioStream(streams, id = "")
2023-05-06 20:54:33 +00:00
preferredLanguage = get_user_setting("display.playback.AudioLanguagePreference")
playDefault = get_user_setting("display.playback.PlayDefaultAudioTrack")
2023-05-06 20:34:17 +00:00
2023-05-06 21:35:16 +00:00
' Do we already have the MediaStreams or not?
if streams = invalid
userId = get_setting("active_user")
url = Substitute("Users/{0}/Items/{1}", userId, id)
resp = APIRequest(url)
jsonResponse = getJson(resp)
if jsonResponse <> invalid and jsonResponse.MediaStreams <> invalid
streams = jsonResponse.MediaStreams
else
' we can't find the streams? return the default track
return 1
end if
end if
2023-05-06 20:54:33 +00:00
if playDefault <> invalid and playDefault = "true"
return 1
end if
2023-05-06 20:34:17 +00:00
2023-05-06 20:54:33 +00:00
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
2023-05-06 20:34:17 +00:00
2023-05-06 20:54:33 +00:00
return 1
2023-05-06 20:34:17 +00:00
end function