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 @@
+
+
-
diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs
index eb47a7b5..02e6c2bb 100644
--- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs
+++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.bs
@@ -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
diff --git a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml
index 84c910ed..62e2c9cc 100644
--- a/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml
+++ b/playlet-lib/src/components/VideoPlayerDev/VideoPlayerDev.xml
@@ -9,8 +9,9 @@
+
+
-