From b683c15a420bec4876e67fe694af752faf6f5c1a Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Sun, 29 Nov 2020 16:37:11 +0100 Subject: [PATCH] Show total duration of playlist in ready state --- .../content/pad/ContentPlayerPadContent.scala | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 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 74907748..76c1b4c4 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 @@ -12,6 +12,7 @@ import de.tobias.playpad.plugin.content.settings.PlayerInstance import de.tobias.playpad.plugin.content.util._ import de.tobias.playpad.volume.VolumeManager import javafx.application.Platform +import javafx.beans.binding.{Bindings, ObjectBinding} import javafx.beans.property._ import javafx.collections.{FXCollections, ObservableList} import javafx.scene.media.{Media, MediaPlayer} @@ -65,8 +66,7 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte mediaPlayer.stop() ContentPluginMain.playerViewController.disconnectMediaPlayer(mediaPlayer, getSelectedZones) - _durationProperty.unbind() - _durationProperty.set(Duration.ZERO) + _durationProperty.bind(totalDurationBinding()) _positionProperty.unbind() _positionProperty.set(Duration.ZERO) } @@ -155,6 +155,26 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte override def positionProperty(): ReadOnlyObjectProperty[Duration] = _positionProperty + def totalDurationBinding(): ObjectBinding[Duration] = { + Bindings.createObjectBinding(() => mediaPlayers.stream() + .map(player => player.mediaPlayer.getTotalDuration) + .filter(duration => duration != null) + .reduce(Duration.ZERO, (o1: Duration, o2: Duration) => o1.add(o2)), + mediaPlayers.stream().map(player => { + if (player.mediaPlayer != null) { + player.mediaPlayer.totalDurationProperty() + } else { + null + } + }) + .filter(o => o != null) + .toArray(size => new Array[ReadOnlyObjectProperty[Duration]](size)): _*) + } + + /* + Loading + */ + override def isPadLoaded: Boolean = { mediaPlayers.isNotEmpty } @@ -185,7 +205,7 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte mediaPlayer.setOnReady(() => { getPad.setStatus(PadStatus.READY) - _durationProperty.set(Duration.ZERO) + _durationProperty.bind(totalDurationBinding()) _positionProperty.set(Duration.ZERO) Platform.runLater(() => { -- GitLab