From 4867df729f78d38858a5e6e222940c8180c3a5f5 Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Wed, 8 Dec 2021 16:30:32 +0100 Subject: [PATCH] #180 - Add playlist shuffle mode to content player --- .../option/pad/PlaylistTabViewController.java | 13 +-- .../src/main/resources/lang/ui_de.properties | 2 + .../view/option/pad/PlaylistTab.fxml | 107 +++++++++++------- .../playpad/pad/content/Playlistable.java | 3 + .../pad/ContentPlayerMediaContainer.scala | 8 +- .../content/pad/ContentPlayerPadContent.scala | 9 +- .../content/pad/ContentPlayerPadPreview.scala | 3 +- .../content/player/ContentPlayerBinding.scala | 2 +- 8 files changed, 90 insertions(+), 57 deletions(-) diff --git a/PlayWall/src/main/java/de/tobias/playpad/viewcontroller/option/pad/PlaylistTabViewController.java b/PlayWall/src/main/java/de/tobias/playpad/viewcontroller/option/pad/PlaylistTabViewController.java index 8faa9b35..6eb0738f 100644 --- a/PlayWall/src/main/java/de/tobias/playpad/viewcontroller/option/pad/PlaylistTabViewController.java +++ b/PlayWall/src/main/java/de/tobias/playpad/viewcontroller/option/pad/PlaylistTabViewController.java @@ -4,7 +4,6 @@ import de.thecodelabs.utils.application.system.NativeApplication; import de.thecodelabs.utils.ui.icon.FontAwesomeType; import de.thecodelabs.utils.ui.icon.FontIcon; import de.thecodelabs.utils.util.Localization; -import de.tobias.playpad.PlayPad; import de.tobias.playpad.PlayPadPlugin; import de.tobias.playpad.Strings; import de.tobias.playpad.layout.desktop.listener.PadNewContentListener; @@ -19,10 +18,7 @@ import javafx.beans.binding.Bindings; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Node; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; +import javafx.scene.control.*; import javafx.scene.layout.VBox; import java.io.File; @@ -31,6 +27,9 @@ import java.util.List; public class PlaylistTabViewController extends PadSettingsTabViewController { + @FXML + private CheckBox shuffleCheckbox; + @FXML private ListView<MediaPath> mediaPathListView; @@ -123,12 +122,12 @@ public class PlaylistTabViewController extends PadSettingsTabViewController { @Override public void loadSettings(Pad pad) { - // Not implemented + shuffleCheckbox.setSelected((Boolean) pad.getPadSettings().getCustomSettings().getOrDefault(Playlistable.SHUFFLE_SETTINGS_KEY, false)); } @Override public void saveSettings(Pad pad) { - // Not implemented + pad.getPadSettings().getCustomSettings().put(Playlistable.SHUFFLE_SETTINGS_KEY, shuffleCheckbox.isSelected()); } @FXML diff --git a/PlayWall/src/main/resources/lang/ui_de.properties b/PlayWall/src/main/resources/lang/ui_de.properties index 229c7ab2..39e63dfd 100755 --- a/PlayWall/src/main/resources/lang/ui_de.properties +++ b/PlayWall/src/main/resources/lang/ui_de.properties @@ -137,6 +137,8 @@ padSettings.player.label.cueIn=Intro Dauer (in s): padSettings.player.label.fade=Ein-/Ausblenden: padSettings.layout.label.custom=Eigenes Layout: padSettings.layout.checkbox.custom=Aktiviert +padSettings.playlist.settings.title=Allgemeine Einstellungen +padSettings.playlist.settings.shuffle=Zuf\u00E4llige Wiedergabe project.label.details=Projektinformationen: project.label.name=Name: project.label.profile=Profil: diff --git a/PlayWall/src/main/resources/view/option/pad/PlaylistTab.fxml b/PlayWall/src/main/resources/view/option/pad/PlaylistTab.fxml index dfa32cd7..f0a37ec7 100644 --- a/PlayWall/src/main/resources/view/option/pad/PlaylistTab.fxml +++ b/PlayWall/src/main/resources/view/option/pad/PlaylistTab.fxml @@ -1,46 +1,67 @@ <?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.Insets?> -<?import javafx.scene.control.*?> -<?import javafx.scene.layout.*?> -<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="14.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> - <children> - <VBox spacing="14.0"> - <children> - <ListView fx:id="mediaPathListView" prefWidth="250.0" VBox.vgrow="ALWAYS" /> - <HBox spacing="14.0"> - <children> - <Button fx:id="addButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#onAddHandler" HBox.hgrow="ALWAYS" /> - <Button fx:id="upButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#onUpHandler" HBox.hgrow="ALWAYS" /> - <Button fx:id="downButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#onDownAction" HBox.hgrow="ALWAYS" /> - </children> - </HBox> - </children> - </VBox> - <VBox spacing="14.0"> - <children> - <HBox spacing="14.0"> - <children> - <Label fx:id="pathLabel" textOverrun="CENTER_ELLIPSIS" /> - </children> - </HBox> - <HBox spacing="14.0"> - <children> - <Button fx:id="showFileButton" mnemonicParsing="false" onAction="#onShowFileHandler" text="%padSettings.button.path.show" /> - <Button fx:id="deleteButton" mnemonicParsing="false" onAction="#onDeleteHandler" text="%padSettings.button.delete" /> - </children> - </HBox> - <VBox fx:id="customItemView" /> - </children> - <HBox.margin> - <Insets /> - </HBox.margin> - <padding> - <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> - </padding> - </VBox> - </children> - <padding> - <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> - </padding> -</HBox> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.CheckBox?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.ListView?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.VBox?> + +<VBox xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"> + <children> + <VBox spacing="14"> + <children> + <Label styleClass="headline" text="%padSettings.playlist.settings.title" /> + <CheckBox fx:id="shuffleCheckbox" mnemonicParsing="false" text="%padSettings.playlist.settings.shuffle" /> + </children> + <VBox.margin> + <Insets /> + </VBox.margin> + <padding> + <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> + </padding> + </VBox> + <HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="14.0"> + <children> + <VBox spacing="14.0"> + <children> + <ListView fx:id="mediaPathListView" prefWidth="250.0" VBox.vgrow="ALWAYS" /> + <HBox spacing="14.0"> + <children> + <Button fx:id="addButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#onAddHandler" HBox.hgrow="ALWAYS" /> + <Button fx:id="upButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#onUpHandler" HBox.hgrow="ALWAYS" /> + <Button fx:id="downButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#onDownAction" HBox.hgrow="ALWAYS" /> + </children> + </HBox> + </children> + </VBox> + <VBox spacing="14.0"> + <children> + <HBox spacing="14.0"> + <children> + <Label fx:id="pathLabel" textOverrun="CENTER_ELLIPSIS" /> + </children> + </HBox> + <HBox spacing="14.0"> + <children> + <Button fx:id="showFileButton" mnemonicParsing="false" onAction="#onShowFileHandler" text="%padSettings.button.path.show" /> + <Button fx:id="deleteButton" mnemonicParsing="false" onAction="#onDeleteHandler" text="%padSettings.button.delete" /> + </children> + </HBox> + <VBox fx:id="customItemView" /> + </children> + <HBox.margin> + <Insets /> + </HBox.margin> + <padding> + <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> + </padding> + </VBox> + </children> + <padding> + <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> + </padding> + </HBox> + </children> +</VBox> diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/pad/content/Playlistable.java b/PlayWallCore/src/main/java/de/tobias/playpad/pad/content/Playlistable.java index 1d15d9ad..c787b93c 100644 --- a/PlayWallCore/src/main/java/de/tobias/playpad/pad/content/Playlistable.java +++ b/PlayWallCore/src/main/java/de/tobias/playpad/pad/content/Playlistable.java @@ -4,6 +4,9 @@ import de.tobias.playpad.pad.mediapath.MediaPath; import javafx.beans.property.IntegerProperty; public interface Playlistable { + + String SHUFFLE_SETTINGS_KEY = "shuffle"; + int getCurrentPlayingMediaIndex(); IntegerProperty currentPlayingMediaIndexProperty(); 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 index e524e428..93d34c1c 100644 --- 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 @@ -8,7 +8,7 @@ import de.tobias.playpad.plugin.content.util._ import javafx.beans.property.{ObjectProperty, ReadOnlyObjectProperty, SimpleObjectProperty} import javafx.util.Duration -import java.nio.file.Files +import java.nio.file.{Files, Path} class ContentPlayerMediaContainer(val content: ContentPlayerPadContent, private[pad] val mediaPath: MediaPath, val totalDuration: Duration) { @@ -16,17 +16,17 @@ class ContentPlayerMediaContainer(val content: ContentPlayerPadContent, private[ _totalDurationProperty.set(totalDuration) - def getPath: String = { + def getPath: Path = { val sourcePath = mediaPath.getPath.toAbsolutePath val globalSettings = PlayPadPlugin.getInstance.getGlobalSettings val convertPath = globalSettings.getCachePath.resolve(sourcePath.getFileName + ".mp4") if (Files.exists(convertPath)) { - return convertPath.toString + return convertPath } - sourcePath.toString + sourcePath } def getTotalDuration: Duration = _totalDurationProperty.get() 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 f6eb4ba5..48bf1188 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 @@ -20,7 +20,7 @@ import nativecontentplayerwindows.ContentPlayer import java.nio.file.Files import java.util -import java.util.UUID +import java.util.{Collections, UUID} import java.util.stream.Collectors import scala.jdk.CollectionConverters._ @@ -61,6 +61,9 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte if (isPause) { mediaPlayers(getCurrentPlayingMediaIndex).resume(withFadeIn) } else { + if (isShuffle) { + Collections.shuffle(mediaPlayers) + } getPad.setEof(false) mediaPlayers.head.play(withFadeIn) } @@ -296,6 +299,10 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte pad.getPadSettings.getCustomSettings.getOrDefault(ContentPlayerPadContentFactory.lastFrame, false).asInstanceOf[Boolean] } + def isShuffle: Boolean = { + pad.getPadSettings.getCustomSettings.getOrDefault(Playlistable.SHUFFLE_SETTINGS_KEY, false).asInstanceOf[Boolean] + } + def getSelectedZones: Seq[Zone] = { val zoneConfiguration = Profile.currentProfile().getCustomSettings(ContentPluginMain.zoneConfigurationKey).asInstanceOf[ContentPlayerPluginConfiguration] diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadPreview.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadPreview.scala index 6ff29819..cbc98c23 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadPreview.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadPreview.scala @@ -43,7 +43,8 @@ class ContentPlayerPadPreview(pad: Pad, parent: Pane) extends VBox with IPadCont pad.getContent match { case content: ContentPlayerPadContent => subTitleLabel.textProperty().bind(Bindings.createStringBinding(() => { - if (content.getCurrentPlayingMediaIndex < 0) "" else PathUtils.getFilenameWithoutExtension(pad.getPaths.get(content.getCurrentPlayingMediaIndex).getPath.getFileName) + if (content.getCurrentPlayingMediaIndex < 0) "" + else PathUtils.getFilenameWithoutExtension(content.getMediaContainers.get(content.getCurrentPlayingMediaIndex).getPath.getFileName) }, content.currentPlayingMediaIndexProperty())) case _ => } 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 44dd4a25..9484ac9b 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 @@ -51,7 +51,7 @@ class ContentPlayerBinding(val nativePlayer: ContentPlayer, val zone: Zone) { currentMedia.get().content.getPad.stop() } } - nativePlayer.Play(media.getPath, withFadeIn) + nativePlayer.Play(media.getPath.toString, withFadeIn) currentMedia.set(media) } -- GitLab