package at.fhtw.mcs.util;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.UnsupportedAudioFileException;

/**
 * This class centralizes management of audio output. It maintains the selected
 * {@link Mixer} and is reponsible for opening {@link Clip}s.
 *
 */
public class AudioOuput {

	private AudioOuput() {
		// no instances allowed
	}

	private static Mixer.Info selectedMixerInfo = AudioSystem.getMixerInfo()[0];

	public static Clip openClip(File file) {
		try {
			AudioInputStream audioIn = AudioSystem.getAudioInputStream(file);
			Clip clip = AudioSystem.getClip(selectedMixerInfo);
			clip.open(audioIn);
			return clip;
		} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
			throw new RuntimeException("Error while opening clip", e);
		}
	}

	public static Mixer.Info getSelectedMixerInfo() {
		return selectedMixerInfo;
	}

	public static void setSelectedMixerInfo(Mixer.Info selectedMixerInfo) {
		AudioOuput.selectedMixerInfo = selectedMixerInfo;
	}
}

@@ -334,16 +334,115 @@
 ption;%0A%0A
+import at.fhtw.mcs.model.Format;%0Aimport at.fhtw.mcs.util.TrackFactory.UnsupportedFormatException;%0A%0A
 /**%0A * T
@@ -792,17 +792,8 @@
 ) %7B%0A
-%09%09try %7B%0A%09
 %09%09Au
@@ -816,16 +816,43 @@
 udioIn =
+ null;%0A%09%09try %7B%0A%09%09%09audioIn =
  AudioSy
@@ -1024,22 +1024,8 @@
 n %7C 
-IOException %7C 
 Line
@@ -1027,32 +1027,134 @@
  LineUnavailable
+Exception e) %7B%0A%09%09%09throw new UnsupportedFormatException(Format.WAV, audioIn.getFormat());%0A%09%09%7D catch (IO
 Exception e) %7B%0A%09

fix merge bug in openClip