package at.ac.tuwien.dsg.pubsub.subscriber.comp.socket;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;

import at.ac.tuwien.dsg.pubsub.message.Message;
import at.ac.tuwien.dsg.pubsub.subscriber.comp.MessageConsumer;

public class AudioMessageConsumer extends MessageConsumer<byte[]> {

    SourceDataLine audioLine;

    @Override
    public void consume(Message<byte[]> msg) {
        switch (msg.getType()) {
        case TOPIC:
            break;
        case INIT:
            try {
                AudioInputStream in = AudioSystem.getAudioInputStream(new ByteArrayInputStream(msg.getData()));
                audioLine = AudioSystem.getSourceDataLine(in.getFormat());
                audioLine.open();
                audioLine.start();
            } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
                audioLine = null;
            }
            break;
        case DATA:
            if (audioLine != null) {
                audioLine.write(msg.getData(), 0, msg.getData().length);
            }
            break;
        case CLOSE:
            if (audioLine != null) {
                audioLine.stop();
                audioLine.close();
            }
        case ERROR:
        default:
            audioLine = null;
            break;
        }
    }

    @Override
    public void end() {
        if (audioLine != null) {
            audioLine.stop();
            audioLine.close();
        }
    }

}

@@ -1392,191 +1392,85 @@
     
-    if (audioLine != null) %7B%0D%0A                audioLine.stop();%0D%0A                audioLine.close();%0D%0A            %7D%0D%0A        case ERROR:%0D%0A        default:%0D%0A            audioLine = null
+case ERROR:%0D%0A        default:%0D%0A            end();%0D%0A            System.exit(0)
 ;%0D%0A 

simplified the AudioMessageConsumer