import net.pterodactylus.sonitus.data.ConnectException;
import net.pterodactylus.sonitus.data.Connection;
-import net.pterodactylus.sonitus.data.Format;
+import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Sink;
import net.pterodactylus.sonitus.data.Source;
/**
- * {@link Sink} implementation that uses the JDK’s {@link javax.sound.sampled.AudioSystem} to play all {@link
- * net.pterodactylus.sonitus.data.Source}s.
+ * {@link Sink} implementation that uses the JDK’s {@link
+ * javax.sound.sampled.AudioSystem} to play all {@link net.pterodactylus.sonitus.data.Source}s.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
@Override
public void connect(Source source) throws ConnectException {
checkNotNull(source, "source must not be null");
- checkState(source.format().encoding().equalsIgnoreCase("PCM"), "source must be PCM-encoded");
+ checkState(source.metadata().encoding().equalsIgnoreCase("PCM"), "source must be PCM-encoded");
- final Format sourceFormat = source.format();
- AudioFormat audioFormat = new AudioFormat(sourceFormat.frequency(), 16, sourceFormat.channels(), true, false);
+ final Metadata sourceMetadata = source.metadata();
+ AudioFormat audioFormat = new AudioFormat(sourceMetadata.frequency(), 16, sourceMetadata.channels(), true, false);
try {
final SourceDataLine sourceDataLine = AudioSystem.getSourceDataLine(audioFormat);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
new Thread(new Connection(source) {
+
@Override
protected int bufferSize() {
- return sourceFormat.channels() * sourceFormat.frequency() * 2;
+ return sourceMetadata.channels() * sourceMetadata.frequency() * 2;
}
@Override
sourceDataLine.write(buffer, 0, buffer.length);
logger.finest(String.format("AudioSink: Wrote %d Bytes.", buffer.length));
}
+
+ @Override
+ protected void finish() {
+ sourceDataLine.stop();
+ }
}).start();
- }
- catch (LineUnavailableException lue1) {
+ } catch (LineUnavailableException lue1) {
throw new ConnectException(lue1);
}
}
+ @Override
+ public void metadataUpdated() {
+ /* ignore. */
+ }
+
}