Skip to content

Commit

Permalink
Fix failed to create media player error (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
iBicha committed May 23, 2024
1 parent 55c811a commit 1acf1da
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- A bug where bookmarked channels can be duplicated
- A bug where video cast from web app would not play if there's an error dialog on screen
- failed to create media player error, by waiting for previous video to stop before starting a new one

### Changed

Expand Down
46 changes: 44 additions & 2 deletions playlet-lib/src/components/VideoPlayer/VideoPlayer.bs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,51 @@ function OnVideoContentTaskResults(output as object) as void
end if
end if

m.top.control = "play"
PlayAfterPreviousPlayerHasStopped()

if hasTimestamp and timestamp > 0
m.top.seek = content.timestamp
end if
end function

function PlayAfterPreviousPlayerHasStopped() as void
previousPlayer = m.top.previousPlayer
m.top.previousPlayer = invalid

if previousPlayer = invalid
m.top.control = "play"
return
end if

previousPlayerState = previousPlayer.state
LogInfo("Previous player state:", previousPlayerState)

if previousPlayerState = "stopping"
previousPlayer.observeFieldScoped("state", FuncName(OnPreviousPlayerState))
return
end if

m.top.control = "play"
end function

function OnPreviousPlayerState(event as object) as void
previousPlayer = event.getRoSGNode()

if m.onCloseCalled = true
previousPlayer.unobserveFieldScoped("state")
return
end if

previousPlayerState = previousPlayer.state
LogInfo("Previous player state change:", previousPlayerState)

if previousPlayerState = "stopped" or previousPlayerState = "error" or previousPlayerState = "finished" or previousPlayerState = "none"
previousPlayer.unobserveFieldScoped("state")

m.top.control = "play"
end if
end function

function OnVideoContentTaskErrorDialogResponse(event as object)
dialog = event.getRoSGNode()
dialog.unobserveFieldScoped("wasClosed")
Expand All @@ -185,7 +223,11 @@ function MarkVideoWatched(videoId as string)
end if
end function

function Close(_unused as dynamic)
function OnClose()
m.onCloseCalled = true

m.top.previousPlayer = invalid

if m.videoContentTask <> invalid
m.videoContentTask.cancel = true
m.videoContentTask = invalid
Expand Down
3 changes: 2 additions & 1 deletion playlet-lib/src/components/VideoPlayer/VideoPlayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<field id="invidious" type="node" bind="../../Invidious" />
<field id="webServer" type="node" bind="../../WebServer" />
<field id="loungeService" type="node" bind="../../LoungeService" />
<field id="previousPlayer" type="node" />
<field id="minRect" type="rect2D" value="[834,460,426,240]" />
<field id="maxRect" type="rect2D" value="[0,0,1280,720]" />
<field id="chapter" type="string" alias="chapterLabel.text" />
<field id="showFullScreenHint" type="boolean" alwaysNotify="true" onChange="OnShowFullScreenHint" />
<field id="close" type="boolean" alwaysNotify="true" onChange="OnClose" />
<function name="PlayWithContent" />
<function name="Close" />
</interface>
<children>
<Label id="chapterLabel" width="350" height="25" horizAlign="center" vertAlign="center" font="font:SmallestSystemFont" />
Expand Down
6 changes: 4 additions & 2 deletions playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ function OnVideoContentTaskResults(output as object) as void
end if
error = ErrorUtils.Format(error)
LogError(error)
Close(invalid)
m.top.close = true
return
end if

m.top.control = "play"
end function

function Close(_unused as dynamic)
function OnClose()
m.top.previousPlayer = invalid

if m.videoContentTask <> invalid
m.videoContentTask.cancel = true
m.videoContentTask = invalid
Expand Down
3 changes: 2 additions & 1 deletion playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<interface>
<field id="videoQueue" type="node" bind="../../VideoQueue" />
<field id="invidious" type="node" bind="../../Invidious" />
<field id="previousPlayer" type="node" />
<field id="close" type="boolean" alwaysNotify="true" onChange="OnClose" />
<function name="PlayWithContent" />
<function name="Close" />
</interface>
<children>
<SimpleLabel
Expand Down
4 changes: 3 additions & 1 deletion playlet-lib/src/components/VideoQueue/VideoQueue.bs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ function OnClosePlayer() as void
return
end if

player@.Close()
player.close = true
m.top.player = invalid
m.previousPlayer = player

m.top.appController@.FocusTopScreen()
end function
Expand Down Expand Up @@ -365,6 +366,7 @@ function CreateVideoPlayer() as object
container = m.top.videoContainer
videoPlayer = container.createChild(playerComponent)
videoPlayer.id = "VideoPlayer"
videoPlayer.previousPlayer = m.previousPlayer
videoPlayer@.BindNode()

if container.fullscreen
Expand Down

0 comments on commit 1acf1da

Please sign in to comment.