Files
ReplayModCinematic/src/main/java/com/replaymod/render/utils/SoundHandler.java
johni0702 edf57490a6 Remove lots of old code
Add some additional config settings
Update jGui and ReplayStudio
2016-08-15 22:18:33 +02:00

40 lines
1.3 KiB
Java

package com.replaymod.render.utils;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.io.IOUtils;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
public class SoundHandler {
private final ResourceLocation successSoundLocation = new ResourceLocation("replaymod", "renderSuccess.wav");
public void playRenderSuccessSound() {
playSound(successSoundLocation);
}
/**
* Plays a <b>.wav</b> Sound from a ResourceLocation. This method does <b>not</b> respect Game Settings like Audio Volume.
* @param loc The Sound File's ResourceLocation
*/
public void playSound(ResourceLocation loc) {
try {
InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream();
byte[] bytes = IOUtils.toByteArray(is);
is.close();
AudioInputStream ais = AudioSystem.getAudioInputStream(new ByteArrayInputStream(bytes));
Clip clip = AudioSystem.getClip();
clip.open(ais);
clip.start();
} catch(Exception e) {
e.printStackTrace();
}
}
}