Don’t change the title, just set the content.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / filter / TimeCounterFilter.java
index faff0bd..96b4052 100644 (file)
@@ -43,7 +43,7 @@ public class TimeCounterFilter extends DummyFilter {
        private final boolean resetOnMetadataUpdate;
 
        /** The last displayed timestamp. */
-       private final AtomicLong lastTimestamp = new AtomicLong(0);
+       private final AtomicLong lastTimestamp = new AtomicLong(-1);
 
        /**
         * Creates a new time counter filter that automatically resets the counter when
@@ -100,20 +100,30 @@ public class TimeCounterFilter extends DummyFilter {
 
        @Override
        public void metadataUpdated(Metadata metadata) {
-               super.metadataUpdated(metadata);
                parentMetadata.set(metadata);
                if (resetOnMetadataUpdate) {
                        reset();
                }
+               updateTimestamp();
        }
 
        @Override
        public void process(byte[] buffer) throws IOException {
                super.process(buffer);
                counter.getAndAdd(buffer.length);
+               updateTimestamp();
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /** Updates the timestamp in the metadata. */
+       private void updateTimestamp() {
                long timestamp = getMillis() / 1000;
                if (lastTimestamp.get() != timestamp) {
-                       super.metadataUpdated(parentMetadata.get().title(String.format("%s (%02d:%02d)", parentMetadata.get().title(), timestamp / 60, timestamp % 60)));
+                       super.metadataUpdated(parentMetadata.get().comment(String.format("%02d:%02d", timestamp / 60, timestamp % 60)));
+                       lastTimestamp.set(timestamp);
                }
        }