Skip to content
Snippets Groups Projects
Commit 61e25b3b authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Extract MediaPlayerStack into separate class

parent 51035c52
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import de.thecodelabs.plugins.PluginDescriptor
import de.thecodelabs.storage.settings.{Storage, StorageTypes}
import de.thecodelabs.utils.util.Localization
import de.tobias.playpad.PlayPadPlugin
import de.tobias.playpad.plugin.content.player.ContentPlayerViewController
import de.tobias.playpad.plugin.content.settings.{PlayerInstanceConfiguration, PlayerInstanceSettingsViewController}
import de.tobias.playpad.plugin.{Module, PlayPadPluginStub}
import javafx.application.Platform
......
package de.tobias.playpad.plugin.content
import java.util.stream.Collectors
package de.tobias.playpad.plugin.content.player
import de.thecodelabs.logger.Logger
import de.thecodelabs.utils.ui.NVC
......@@ -9,80 +7,15 @@ import de.tobias.playpad.plugin.content.settings.{PlayerInstance, PlayerInstance
import de.tobias.playpad.project.page.PadIndex
import javafx.geometry.Insets
import javafx.scene.layout._
import javafx.scene.media.{MediaPlayer, MediaView}
import javafx.scene.media.MediaPlayer
import javafx.scene.paint.Color
import javafx.stage.{Stage, StageStyle}
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
@IgnoreStageSizing
class ContentPlayerViewController extends NVC {
private class MediaPlayerStack(val playerInstance: PlayerInstance) extends StackPane {
private var activePlayers: ListBuffer[PadIndex] = ListBuffer.empty
val mediaViews: mutable.Map[MediaPlayer, MediaView] = new mutable.HashMap[MediaPlayer, MediaView]()
setLayoutX(playerInstance.x)
setLayoutY(playerInstance.y)
setMinWidth(playerInstance.width)
setMaxWidth(playerInstance.width)
setMinHeight(playerInstance.height)
setMaxHeight(playerInstance.height)
def addActivePad(padIndex: PadIndex): Unit = activePlayers.addOne(padIndex)
def removeActivePad(padIndex: PadIndex): Unit = activePlayers = activePlayers.filter(element => element != padIndex)
def showMediaPlayer(padIndex: PadIndex, mediaPlayer: MediaPlayer): Unit = {
if (!mediaViews.contains(mediaPlayer)) {
val mediaView = new MediaView(mediaPlayer)
mediaView.setFitWidth(playerInstance.width)
mediaView.setFitHeight(playerInstance.height)
mediaViews.put(mediaPlayer, mediaView)
}
val mediaView = mediaViews(mediaPlayer)
mediaView.setUserData(padIndex)
mediaView.setOpacity(1.0)
if (!getChildren.contains(mediaView)) {
val index = activePlayers.indexOf(padIndex)
try {
getChildren.add(index, mediaView)
} catch {
case e: Exception =>
Logger.error(e)
getChildren.add(mediaView)
}
}
}
def disconnectMediaPlayer(mediaPlayer: MediaPlayer): Unit = {
if (mediaViews.contains(mediaPlayer)) {
getChildren.remove(mediaViews(mediaPlayer))
}
}
def setFadeValue(mediaPlayer: MediaPlayer, value: Double): Unit = {
if (mediaViews.contains(mediaPlayer)) {
val mediaView = mediaViews(mediaPlayer)
mediaView.setOpacity(value)
}
}
def highlight(on: Boolean): Unit = {
if (on) {
setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)))
} else {
setBackground(null)
}
}
override def toString: String = f"MediaPlayerStack: ${getChildren.stream().map(view => f"MediaView: ${view.getUserData}").collect(Collectors.joining(", "))}"
}
private val mediaStacks: ListBuffer[MediaPlayerStack] = ListBuffer.empty
load("view", "PlayerView")
......
package de.tobias.playpad.plugin.content.player
import java.util.stream.Collectors
import de.thecodelabs.logger.Logger
import de.tobias.playpad.plugin.content.settings.PlayerInstance
import de.tobias.playpad.project.page.PadIndex
import javafx.geometry.Insets
import javafx.scene.layout.{Background, BackgroundFill, CornerRadii, StackPane}
import javafx.scene.media.{MediaPlayer, MediaView}
import javafx.scene.paint.Color
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
class MediaPlayerStack(val playerInstance: PlayerInstance) extends StackPane {
private var activePlayers: ListBuffer[PadIndex] = ListBuffer.empty
val mediaViews: mutable.Map[MediaPlayer, MediaView] = new mutable.HashMap[MediaPlayer, MediaView]()
setLayoutX(playerInstance.x)
setLayoutY(playerInstance.y)
setMinWidth(playerInstance.width)
setMaxWidth(playerInstance.width)
setMinHeight(playerInstance.height)
setMaxHeight(playerInstance.height)
def addActivePad(padIndex: PadIndex): Unit = activePlayers.addOne(padIndex)
def removeActivePad(padIndex: PadIndex): Unit = activePlayers = activePlayers.filter(element => element != padIndex)
def showMediaPlayer(padIndex: PadIndex, mediaPlayer: MediaPlayer): Unit = {
if (!mediaViews.contains(mediaPlayer)) {
val mediaView = new MediaView(mediaPlayer)
mediaView.setFitWidth(playerInstance.width)
mediaView.setFitHeight(playerInstance.height)
mediaViews.put(mediaPlayer, mediaView)
}
val mediaView = mediaViews(mediaPlayer)
mediaView.setUserData(padIndex)
mediaView.setOpacity(1.0)
if (!getChildren.contains(mediaView)) {
val index = activePlayers.indexOf(padIndex)
try {
getChildren.add(index, mediaView)
} catch {
case e: Exception =>
Logger.error(e)
getChildren.add(mediaView)
}
}
}
def disconnectMediaPlayer(mediaPlayer: MediaPlayer): Unit = {
if (mediaViews.contains(mediaPlayer)) {
getChildren.remove(mediaViews(mediaPlayer))
}
}
def setFadeValue(mediaPlayer: MediaPlayer, value: Double): Unit = {
if (mediaViews.contains(mediaPlayer)) {
val mediaView = mediaViews(mediaPlayer)
mediaView.setOpacity(value)
}
}
def highlight(on: Boolean): Unit = {
if (on) {
setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)))
} else {
setBackground(null)
}
}
override def toString: String = f"MediaPlayerStack: ${getChildren.stream().map(view => f"MediaView: ${view.getUserData}").collect(Collectors.joining(", "))}"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment