From f24709cf03cc47cfdfb629683c3a8fdc25b1abae Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Tue, 1 Dec 2020 09:49:16 +0100 Subject: [PATCH] Extract ContentPlayerMediaContainer into separate class --- .../pad/ContentPlayerMediaContainer.scala | 63 ++++++++++++++++ .../content/pad/ContentPlayerPadContent.scala | 74 ++++--------------- 2 files changed, 78 insertions(+), 59 deletions(-) create mode 100644 PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerMediaContainer.scala diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerMediaContainer.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerMediaContainer.scala new file mode 100644 index 00000000..74f74fae --- /dev/null +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerMediaContainer.scala @@ -0,0 +1,63 @@ +package de.tobias.playpad.plugin.content.pad + +import de.tobias.playpad.pad.PadStatus +import de.tobias.playpad.pad.mediapath.MediaPath +import de.tobias.playpad.plugin.content.ContentPluginMain +import de.tobias.playpad.plugin.content.util._ +import javafx.scene.media.MediaPlayer +import javafx.util.Duration + +class ContentPlayerMediaContainer(val content: ContentPlayerPadContent, val path: MediaPath, val mediaPlayer: MediaPlayer) { + def play(): Unit = { + content._durationProperty.bind(mediaPlayer.totalDurationProperty()) + content._positionProperty.bind(mediaPlayer.currentTimeProperty()) + ContentPluginMain.playerViewController.showMediaPlayer(content.getPad.getPadIndex, mediaPlayer, content.getSelectedZones) + + mediaPlayer.seek(Duration.ZERO) + mediaPlayer.play() + + content.getPad.setEof(false) + + content.currentPlayingMediaIndexProperty().set(content.getMediaPlayers.indexOf(this)) + + val controller = content.getPad.getController + if (controller != null) { + controller.updatePlaylistLabel() + } + } + + def resume(): Unit = { + mediaPlayer.play() + } + + def pause(): Unit = { + mediaPlayer.pause() + } + + def next(): Unit = { + stop() + + val players = content.getMediaPlayers + val index = players.indexOf(this) + content.currentPlayingMediaIndexProperty().set(index) + + if (index + 1 < players.length) { + players(index + 1).play() + } else if (content.getPad.getPadSettings.isLoop) { + players.head.play() + } else { + content.getPad.setStatus(PadStatus.STOP) + } + } + + def stop(): Unit = { + mediaPlayer.stop() + ContentPluginMain.playerViewController.disconnectMediaPlayer(mediaPlayer, content.getSelectedZones) + + content._durationProperty.bind(content.totalDurationBinding()) + content._positionProperty.unbind() + content._positionProperty.set(Duration.ZERO) + } + + override def toString: String = f"MediaPlayerContainer: $path" +} \ No newline at end of file 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 f9835654..b15b2603 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 @@ -24,65 +24,11 @@ import scala.jdk.CollectionConverters._ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadContent(pad) with Pauseable with Durationable with Playlistable with Fadeable { - private class MediaPlayerContainer(val path: MediaPath, val mediaPlayer: MediaPlayer) { - def play(): Unit = { - _durationProperty.bind(mediaPlayer.totalDurationProperty()) - _positionProperty.bind(mediaPlayer.currentTimeProperty()) - ContentPluginMain.playerViewController.showMediaPlayer(getPad.getPadIndex, mediaPlayer, getSelectedZones) - - mediaPlayer.seek(Duration.ZERO) - mediaPlayer.play() - - getPad.setEof(false) - - currentRunningIndexProperty.set(mediaPlayers.indexOf(this)) - - val controller = getPad.getController - if (controller != null) { - controller.updatePlaylistLabel() - } - } - - def resume(): Unit = { - mediaPlayer.play() - } - - def pause(): Unit = { - mediaPlayer.pause() - } - - def next(): Unit = { - stop() - - val index = mediaPlayers.indexOf(this) - currentRunningIndexProperty.set(index) - - if (index + 1 < mediaPlayers.length) { - mediaPlayers(index + 1).play() - } else if (getPad.getPadSettings.isLoop) { - mediaPlayers.head.play() - } else { - getPad.setStatus(PadStatus.STOP) - } - } - - def stop(): Unit = { - mediaPlayer.stop() - ContentPluginMain.playerViewController.disconnectMediaPlayer(mediaPlayer, getSelectedZones) - - _durationProperty.bind(totalDurationBinding()) - _positionProperty.unbind() - _positionProperty.set(Duration.ZERO) - } - - override def toString: String = f"MediaPlayerContainer: $path" - } - - private val mediaPlayers: ObservableList[MediaPlayerContainer] = FXCollections.observableArrayList() + private val mediaPlayers: ObservableList[ContentPlayerMediaContainer] = FXCollections.observableArrayList() private val currentRunningIndexProperty: IntegerProperty = new SimpleIntegerProperty(-1) - private val _durationProperty = new SimpleObjectProperty[Duration] - private val _positionProperty = new SimpleObjectProperty[Duration] + private[pad] val _durationProperty = new SimpleObjectProperty[Duration] + private[pad] val _positionProperty = new SimpleObjectProperty[Duration] private var showingLastFrame: Boolean = false private var isPause: Boolean = false @@ -98,7 +44,13 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte override def currentPlayingMediaIndex: Int = currentRunningIndexProperty.get() - def currentPlayingMediaIndexProperty(): ReadOnlyIntegerProperty = currentRunningIndexProperty + def currentPlayingMediaIndexProperty(): IntegerProperty = currentRunningIndexProperty + + def getMediaPlayers: ObservableList[ContentPlayerMediaContainer] = mediaPlayers + + /* + Control Methods + */ override def play(): Unit = { if (isPause) { @@ -272,7 +224,7 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte onEof() }) - mediaPlayers.add(new MediaPlayerContainer(mediaPath, mediaPlayer)) + mediaPlayers.add(new ContentPlayerMediaContainer(this, mediaPath, mediaPlayer)) } /** @@ -331,6 +283,10 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte clone } + /* + Custom Settings + */ + def shouldShowLastFrame(): Boolean = { pad.getPadSettings.getCustomSettings.getOrDefault(ContentPlayerPadContentFactory.lastFrame, false).asInstanceOf[Boolean] } -- GitLab