From bbf2bc304390be15c9ad3543e692ac6e8a18196c Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Sun, 21 Nov 2021 23:55:34 +0100 Subject: [PATCH] #173 - Resume player before playing next media, keep playing current media than playing new media from different pad --- .../content/pad/ContentPlayerPadContent.scala | 10 ++++++--- .../content/player/ContentPlayerBinding.scala | 21 ++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala index 9ff6ed5c..76089ee8 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala @@ -33,6 +33,8 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte private var showingLastFrame: Boolean = false private var isPause: Boolean = false + var stopMediaByOtherPlayer = false + private val fadeController = new LinearFadeController(value => { if (getCurrentPlayingMediaIndex >= 0) { ContentPluginMain.playerViewController.setFadeValue(getSelectedZones, value) @@ -75,10 +77,12 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte override def stop(): Boolean = { isPause = false - mediaPlayers(getCurrentPlayingMediaIndex).stop() + if (getCurrentPlayingMediaIndex != -1) { + mediaPlayers(getCurrentPlayingMediaIndex).stop() - if (showingLastFrame) { - ContentPluginMain.playerViewController.clearHold(mediaPlayers(getCurrentPlayingMediaIndex)) + if (showingLastFrame) { + ContentPluginMain.playerViewController.clearHold(mediaPlayers(getCurrentPlayingMediaIndex)) + } } currentRunningIndexProperty.set(-1) diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerBinding.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerBinding.scala index d19f4ef0..6b1b9c61 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerBinding.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerBinding.scala @@ -40,6 +40,17 @@ class ContentPlayerBinding(val player: ContentPlayer, val zone: Zone) { }) def play(media: ContentPlayerMediaContainer, withFadeIn: Boolean): Unit = { + if (currentMedia.get() != null && currentMedia.get().content.getPad != media.content.getPad) { + if (currentMedia.get().content.getPad.isPlay) { + // Stop the current playing media on this player and hold the last frame + currentMedia.get().content.stopMediaByOtherPlayer = true + currentMedia.get().content.getPad.stop() + } else if (currentMedia.get().content.getPad.isPaused) { + // The player mist be resumed before playing the next media + player.Resume(withFadeIn) + currentMedia.get().content.getPad.stop() + } + } player.Play(media.getPath, withFadeIn) currentMedia.set(media) } @@ -51,7 +62,15 @@ class ContentPlayerBinding(val player: ContentPlayer, val zone: Zone) { def pause(media: ContentPlayerMediaContainer): Unit = player.Pause() - def stop(media: ContentPlayerMediaContainer): Unit = player.Stop() + def stop(media: ContentPlayerMediaContainer): Unit = { + // If media is stopped by a different pad, the current media should keep playing to have a smooth transition + // to the new media. Otherwise the media will be stopped normally. + if (media.content.stopMediaByOtherPlayer) { + media.content.stopMediaByOtherPlayer = false + } else { + player.Stop() + } + } def clearHold(): Unit = player.ClearHold() -- GitLab