diff --git a/components/JFMessageDialog.brs b/components/JFMessageDialog.brs index a1bef78b..c5c71d3a 100644 --- a/components/JFMessageDialog.brs +++ b/components/JFMessageDialog.brs @@ -4,7 +4,7 @@ end sub function onKeyEvent(key as string, press as boolean) as boolean if key = "OK" - m.top.buttonSelected = 0 + m.top.buttonSelected = m.top.buttonFocused handle_button() return true end if diff --git a/source/VideoPlayer.brs b/source/VideoPlayer.brs index 318141f9..63e9e45e 100644 --- a/source/VideoPlayer.brs +++ b/source/VideoPlayer.brs @@ -19,7 +19,15 @@ function VideoContent(video) as object meta = ItemMetaData(video.id) video.content.title = meta.Name container = getContainerType(meta) - video.PlaySessionId = ItemGetSession(video.id) + + ' If there is a last playback positon, ask user if they want to resume + position = meta.json.UserData.PlaybackPositionTicks + if position > 0 and startPlaybackOver(position) then + position = 0 + end if + video.content.BookmarkPosition = int(position/10000000) + + video.PlaySessionId = ItemGetSession(video.id, position) if directPlaySupported(meta) and decodeAudioSupported(meta) then video.content.url = buildURL(Substitute("Videos/{0}/stream", video.id), { @@ -60,6 +68,11 @@ function VideoContent(video) as object return video end function +'Opens dialog asking user if they want to resume video or start playback over +function startPlayBackOver(time as LongInteger) as boolean + return option_dialog([ "Resume playing at " + ticksToHuman(time) + ".", "Start over from the begining." ]) +end function + function directPlaySupported(meta as object) as boolean devinfo = CreateObject("roDeviceInfo") return devinfo.CanDecodeVideo({ Codec: meta.json.MediaStreams[0].codec }).result diff --git a/source/api/Items.brs b/source/api/Items.brs index e8ab322b..8ae4ba98 100644 --- a/source/api/Items.brs +++ b/source/api/Items.brs @@ -22,10 +22,10 @@ function UserItemsResume(params = {} as object) return data end function -function ItemGetSession(id as string) +function ItemGetSession(id as string, StartTimeTicks = 0 as longinteger) params = { UserId: get_setting("active_user"), - StartTimeTicks: "0", + StartTimeTicks: StartTimeTicks, IsPlayback: "true", AutoOpenLiveStream: "true", MaxStreamingBitrate: "140000000" @@ -35,7 +35,6 @@ function ItemGetSession(id as string) return data.PlaySessionId end function - ' List of available libraries function LibraryList() url = Substitute("Users/{0}/Views/", get_setting("active_user")) diff --git a/source/api/baserequest.brs b/source/api/baserequest.brs index 4653615f..a7fa86ba 100644 --- a/source/api/baserequest.brs +++ b/source/api/baserequest.brs @@ -13,6 +13,8 @@ function buildParams(params={} as Object) as string 'item = field.key + "=" + str(field.value).trim() else if type(field.value) = "roFloat" item = field.key + "=" + stri(int(field.value)).trim() + else if type(field.value) = "LongInteger" + item = field.key + "=" + field.value.toStr().trim() else if type(field.value) = "roArray" ' TODO handle array params else if type(field.value) = "roBoolean" diff --git a/source/utils/misc.brs b/source/utils/misc.brs index 0f7a8b47..d82d8bbd 100644 --- a/source/utils/misc.brs +++ b/source/utils/misc.brs @@ -36,13 +36,25 @@ function leftPad(base as string, fill as string, length as integer) as string return base end function +function ticksToHuman(ticks as longinteger) as string + totalSeconds = int(ticks / 10000000) + hours = stri(int(totalSeconds / 3600)).trim() + minutes = stri(int((totalSeconds - (val(hours)*3600))/60)).trim() + seconds = stri(totalSeconds - (val(hours)*3600) - (val(minutes)*60)).trim() + if val(hours) > 0 and val(minutes) < 10 then minutes = "0" + minutes + if val(seconds) < 10 then seconds = "0" + seconds + r="" + if val(hours) > 0 then r = stri(hours).trim() + ":" + r = r + minutes + ":" + seconds + return r +end function + function div_ceiling(a as integer, b as integer) as integer if a < b then return 1 if int(a/b) = a/b then return a/b end if return a/b + 1 - end function function message_dialog(message = "" as string) @@ -55,3 +67,16 @@ function message_dialog(message = "" as string) m.scene.dialog = dialog m.scene.dialog.setFocus(true) end function + +function option_dialog(options) as integer + dialog = CreateObject("roSGNode", "JFMessageDialog") + dialog.backExitsDialog = false + dialog.buttons = options + m.scene.dialog = dialog + m.scene.dialog.setFocus(true) + + while m.scene.dialog <> invalid + end while + + return dialog.buttonSelected +end function