From f554e51504f7e39e658a84d79c041e0b0d8a6393 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 27 May 2013 09:29:48 +0200 Subject: [PATCH] Expose metadata from every controlled component. --- src/main/java/net/pterodactylus/sonitus/data/Controlled.java | 7 +++++++ .../java/net/pterodactylus/sonitus/data/sink/AudioSink.java | 6 ++++++ .../java/net/pterodactylus/sonitus/data/sink/FileSink.java | 11 ++++++++++- .../net/pterodactylus/sonitus/data/sink/Icecast2Sink.java | 9 +++++++++ .../net/pterodactylus/sonitus/data/source/StreamSource.java | 3 ++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/data/Controlled.java b/src/main/java/net/pterodactylus/sonitus/data/Controlled.java index e311681..6b4c617 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Controlled.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Controlled.java @@ -34,6 +34,13 @@ public interface Controlled { public String name(); /** + * Returns the current metadata of this component. + * + * @return The current metadata of this component + */ + public Metadata metadata(); + + /** * Returns the controllers offered by this component. * * @return The controllers of this component diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java index f7ab938..05253f3 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java @@ -124,6 +124,11 @@ public class AudioSink implements Sink { } @Override + public Metadata metadata() { + return metadata; + } + + @Override public List> controllers() { return Arrays.>asList(volumeFader, muteSwitch); } @@ -155,6 +160,7 @@ public class AudioSink implements Sink { @Override public void metadataUpdated(Metadata metadata) { logger.info(String.format("Now playing %s.", metadata)); + this.metadata = metadata; } @Override diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java index 9bebc6b..92dd59a 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java @@ -43,6 +43,9 @@ public class FileSink implements Sink { private FileOutputStream fileOutputStream; + /** The current metadata. */ + private Metadata metadata; + /** * Creates a new file sink that will write to the given path. * @@ -63,6 +66,11 @@ public class FileSink implements Sink { } @Override + public Metadata metadata() { + return metadata; + } + + @Override public List> controllers() { return Collections.emptyList(); } @@ -74,6 +82,7 @@ public class FileSink implements Sink { @Override public void open(Metadata metadata) throws IOException { fileOutputStream = new FileOutputStream(path); + metadataUpdated(metadata); } @Override @@ -87,7 +96,7 @@ public class FileSink implements Sink { @Override public void metadataUpdated(Metadata metadata) { - /* ignore. */ + this.metadata = metadata; } @Override diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java index 36413f9..5487cc4 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java @@ -78,6 +78,9 @@ public class Icecast2Sink implements Sink { private OutputStream socketOutputStream; + /** The current metadata. */ + private Metadata metadata; + /** * Creates a new Icecast2 sink. * @@ -120,6 +123,11 @@ public class Icecast2Sink implements Sink { } @Override + public Metadata metadata() { + return metadata; + } + + @Override public List> controllers() { return Collections.emptyList(); } @@ -162,6 +170,7 @@ public class Icecast2Sink implements Sink { @Override public void metadataUpdated(final Metadata metadata) { + this.metadata = metadata; new Thread(new Runnable() { @Override diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java index 750642e..9a624e0 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java @@ -144,7 +144,8 @@ public class StreamSource implements Source { if (!streamMetadata.isPresent()) { return metadata; } - return metadata = metadata.title(streamMetadata.get().title()); + metadata = metadata.title(streamMetadata.get().title()); + return metadata; } @Override -- 2.7.4