package util;

public class Audio {
	
	MP3 mp3;
	WAV wav;
	
	public Audio() {
		
	}
	
	public Audio(String fileName) {
		setAudio(fileName);
	}
	
	public void setAudio(String fileName) {
		
		stop();
		
		mp3 = null;
		wav = null;
		
		if(fileName.indexOf('.') != -1) {
			
			if(fileName.substring(fileName.lastIndexOf('.')).equals(".mp3"))
				mp3 = new MP3(fileName);
			
			if(fileName.substring(fileName.lastIndexOf('.')).equals(".wav"))
				wav = new WAV(fileName);
		}
	}
	
	public void play() {
		
		if(mp3 != null)
			mp3.play();
		
		if(wav != null)
			wav.play();
	}
	
	public void play(int loops) {
		
		if(mp3 != null)
			mp3.play(loops);
		
		if(wav != null)
			wav.play(loops);
	}
	
	public void stop() {
		
		if(mp3 != null)
			mp3.stop();
		
		if(wav != null)
			wav.stop();
	}
	
	public boolean isPlaying() {
		
		if(mp3 != null)
			return mp3.isPlaying();
		
		if(wav != null)
			return wav.isPlaying();
		
		return false;
	}
}