Adding bridging of basic MPD operations.

main
Oliver Kennedy 2023-06-04 13:52:54 -04:00
parent badbb1f7e4
commit f8a94890d9
Signed by: okennedy
GPG Key ID: 3E5F9B3ABD3FDB60
1 changed files with 23 additions and 12 deletions

View File

@ -34,6 +34,9 @@ object MPD
lazy val topic =
config("topic").str
lazy val bridge = config.obj.get("bridge").map { _.bool }.getOrElse(false)
lazy val useProxy = config.obj.get("use_proxy").map { _.bool }.getOrElse(false)
lazy val db =
instance.getMusicDatabase()
@ -68,19 +71,25 @@ object MPD
def append(path: String): Boolean =
{
val file = apply(path).getOrElse { return false }
instance.getPlaylist.addSong(file.getPath)
return true
if(useProxy){ Mqtt(s"$topic/commands/append") << path; return true }
else {
val file = apply(path).getOrElse { return false }
instance.getPlaylist.addSong(file.getPath)
return true
}
}
def play(): Unit =
instance.getPlayer.play()
if(useProxy){ Mqtt(s"$topic/commands/play") << "" }
else { instance.getPlayer.play() }
def pause(): Unit =
instance.getPlayer.pause()
if(useProxy){ Mqtt(s"$topic/commands/pause") << "" }
else { instance.getPlayer.pause() }
def clear(): Unit =
instance.getPlaylist.clearPlaylist()
if(useProxy){ Mqtt(s"$topic/commands/clear") << "" }
else { instance.getPlaylist.clearPlaylist() }
case class Song(title: String, artist: String, album: String, position: Int)
object Song
@ -102,16 +111,18 @@ object MPD
override def setup(): Unit =
{
val bridge = config.obj.get("bridge").map { _.bool }.getOrElse(false)
val useProxy = config.obj.get("use_proxy").map { _.bool }.getOrElse(false)
implicit val owner: Owner = Owner.global
if(bridge && !useProxy)
{
Mqtt(s"$topic/status") << status
Mqtt(s"$topic/playlist") << playlist
Mqtt(s"$topic/now_playing") << currentTrack
Mqtt(s"$topic/position") << position
Mqtt(s"$topic/status").isState << status
Mqtt(s"$topic/playlist").isState << playlist
Mqtt(s"$topic/now_playing").isState << currentTrack
Mqtt(s"$topic/position").isState << position
Mqtt(s"$topic/commands/play").trigger { _ => play() }
Mqtt(s"$topic/commands/pause").trigger { _ => pause() }
Mqtt(s"$topic/commands/clear").trigger { _ => clear() }
Mqtt(s"$topic/commands/append").asString.trigger { append(_) }
}
if(useProxy)
{