From 1acf1da00dd1cec955fbe6246a302317c5be2e85 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Thu, 23 May 2024 13:11:35 -0400 Subject: [PATCH] Fix failed to create media player error (#385) --- CHANGELOG.md | 1 + .../src/components/VideoPlayer/VideoPlayer.bs | 46 ++++++++++++++++++- .../components/VideoPlayer/VideoPlayer.xml | 3 +- .../VideoPlayerDev/VideoPlayerDev.bs | 6 ++- .../VideoPlayerDev/VideoPlayerDev.xml | 3 +- .../src/components/VideoQueue/VideoQueue.bs | 4 +- 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1b99cd2..9be94eea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs index 09d01ace..48131493 100644 --- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs +++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs @@ -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") @@ -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 diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml index d76a9ebd..62d985a8 100644 --- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml +++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml @@ -8,12 +8,13 @@ + + -