Use vanilla sound engine to play render success sound (fixes #286)

This commit is contained in:
Jonas Herzig
2021-02-17 03:39:19 +01:00
parent 5f0218929b
commit 56e5df65d5
6 changed files with 28 additions and 41 deletions

View File

@@ -1,39 +0,0 @@
package com.replaymod.render.utils;
import com.replaymod.core.versions.MCVer;
import net.minecraft.util.Identifier;
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 Identifier successSoundLocation = new Identifier("replaymod", "render_success.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(Identifier loc) {
try {
InputStream is = MCVer.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();
}
}
}