Create all controlled components with an event bus.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / sink / AudioSink.java
index d95df6e..a0a4c6a 100644 (file)
@@ -39,6 +39,7 @@ import net.pterodactylus.sonitus.data.controller.Switch;
 import net.pterodactylus.sonitus.io.IntegralWriteOutputStream;
 
 import com.google.common.base.Preconditions;
+import com.google.common.eventbus.EventBus;
 
 /**
  * {@link Sink} implementation that uses the JDK’s {@link AudioSystem} to play
@@ -51,6 +52,9 @@ public class AudioSink implements Sink {
        /** The logger. */
        private static final Logger logger = Logger.getLogger(AudioSink.class.getName());
 
+       /** The event bus. */
+       private final EventBus eventBus;
+
        /** The volume fader. */
        private final Fader volumeFader;
 
@@ -83,9 +87,14 @@ public class AudioSink implements Sink {
                }
        }, 1024);
 
-       /** Creates a new audio sink. */
-       public AudioSink() {
-               super();
+       /**
+        * Creates a new audio sink.
+        *
+        * @param eventBus
+        *              The event bus
+        */
+       public AudioSink(EventBus eventBus) {
+               this.eventBus = eventBus;
                volumeFader = new Fader("Volume") {
 
                        @Override
@@ -120,6 +129,16 @@ public class AudioSink implements Sink {
        //
 
        @Override
+       public String name() {
+               return "Audio Output";
+       }
+
+       @Override
+       public Metadata metadata() {
+               return metadata;
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Arrays.<Controller<?>>asList(volumeFader, muteSwitch);
        }
@@ -151,6 +170,7 @@ public class AudioSink implements Sink {
        @Override
        public void metadataUpdated(Metadata metadata) {
                logger.info(String.format("Now playing %s.", metadata));
+               this.metadata = metadata;
        }
 
        @Override