mirror of
https://github.com/SPAWNRYS-ban/FUCK-CustomDiscs.git
synced 2025-12-10 13:30:24 +05:00
Update PlayerManager.java
This commit is contained in:
@@ -81,8 +81,10 @@ public class PlayerManager {
|
|||||||
|
|
||||||
executorService.execute(() -> {
|
executorService.execute(() -> {
|
||||||
AudioPlayer audioPlayer = null;
|
AudioPlayer audioPlayer = null;
|
||||||
|
AudioInputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
audioPlayer = playChannel(api, audioChannel, block, soundFilePath, playersInRange);
|
inputStream = getAudioInputStream(soundFilePath, FORMAT);
|
||||||
|
audioPlayer = playChannel(api, audioChannel, block, inputStream, playersInRange);
|
||||||
} catch (UnsupportedAudioFileException | IOException e) {
|
} catch (UnsupportedAudioFileException | IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -90,7 +92,13 @@ public class PlayerManager {
|
|||||||
playerMap.remove(id);
|
playerMap.remove(id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
AudioInputStream finalInputStream = inputStream;
|
||||||
audioPlayer.setOnStopped(() -> {
|
audioPlayer.setOnStopped(() -> {
|
||||||
|
try {
|
||||||
|
finalInputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
//plugin.getServer().getRegionScheduler().run(plugin, block.getLocation(), scheduledTask -> HopperManager.instance().discToHopper(block));
|
//plugin.getServer().getRegionScheduler().run(plugin, block.getLocation(), scheduledTask -> HopperManager.instance().discToHopper(block));
|
||||||
if (playerMap.containsValue(playerReference)) {
|
if (playerMap.containsValue(playerReference)) {
|
||||||
playerMap.remove(id);
|
playerMap.remove(id);
|
||||||
@@ -108,9 +116,8 @@ public class PlayerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private de.maxhenkel.voicechat.api.audiochannel.AudioPlayer playChannel(VoicechatServerApi api, AudioChannel audioChannel, Block block, Path soundFilePath, Collection<ServerPlayer> playersInRange) throws UnsupportedAudioFileException, IOException {
|
private de.maxhenkel.voicechat.api.audiochannel.AudioPlayer playChannel(VoicechatServerApi api, AudioChannel audioChannel, Block block, AudioInputStream inputStream, Collection<ServerPlayer> playersInRange) throws UnsupportedAudioFileException, IOException {
|
||||||
//short[] audio = readSoundFile(soundFilePath);
|
//short[] audio = readSoundFile(soundFilePath);
|
||||||
AudioInputStream inputStream = getAudioInputStream(soundFilePath, FORMAT);
|
|
||||||
AudioPlayer audioPlayer = api.createAudioPlayer(audioChannel, api.createEncoder(), () -> {
|
AudioPlayer audioPlayer = api.createAudioPlayer(audioChannel, api.createEncoder(), () -> {
|
||||||
try {
|
try {
|
||||||
return readSoundFile(inputStream);
|
return readSoundFile(inputStream);
|
||||||
@@ -151,36 +158,12 @@ public class PlayerManager {
|
|||||||
return finalInputStream;
|
return finalInputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static short[] readSoundFile(AudioInputStream inputStream) throws UnsupportedAudioFileException, IOException {
|
private static short[] readSoundFile(AudioInputStream inputStream) throws IOException {
|
||||||
return VoicePlugin.voicechatApi.getAudioConverter().bytesToShorts(getAudioPacket(inputStream));
|
return VoicePlugin.voicechatApi.getAudioConverter().bytesToShorts(getAudioPacket(inputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] getAudioPacket(AudioInputStream inputStream) throws UnsupportedAudioFileException, IOException {
|
private static byte[] getAudioPacket(AudioInputStream inputStream) throws IOException {
|
||||||
|
|
||||||
|
|
||||||
/*if (getFileExtension(file.toFile().toString()).equals("wav")) {
|
|
||||||
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file.toFile());
|
|
||||||
finalInputStream = AudioSystem.getAudioInputStream(audioFormat, inputStream);
|
|
||||||
} else if (getFileExtension(file.toFile().toString()).equals("mp3")) {
|
|
||||||
|
|
||||||
AudioInputStream inputStream = new MpegAudioFileReader().getAudioInputStream(file.toFile());
|
|
||||||
AudioFormat baseFormat = inputStream.getFormat();
|
|
||||||
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getFrameRate(), false);
|
|
||||||
AudioInputStream convertedInputStream = new MpegFormatConversionProvider().getAudioInputStream(decodedFormat, inputStream);
|
|
||||||
finalInputStream = AudioSystem.getAudioInputStream(audioFormat, convertedInputStream);
|
|
||||||
|
|
||||||
} else if (getFileExtension(file.toFile().toString()).equals("flac")) {
|
|
||||||
AudioInputStream inputStream = new FlacAudioFileReader().getAudioInputStream(file.toFile());
|
|
||||||
AudioFormat baseFormat = inputStream.getFormat();
|
|
||||||
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getFrameRate(), false);
|
|
||||||
AudioInputStream convertedInputStream = new Flac2PcmAudioInputStream(inputStream, decodedFormat, inputStream.getFrameLength());
|
|
||||||
finalInputStream = AudioSystem.getAudioInputStream(audioFormat, convertedInputStream);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//assert finalInputStream != null;
|
|
||||||
|
|
||||||
byte[] audioPacket = inputStreamToPackets(inputStream);
|
byte[] audioPacket = inputStreamToPackets(inputStream);
|
||||||
|
|
||||||
return adjustVolume(audioPacket, CustomDiscs.getInstance().musicDiscVolume);
|
return adjustVolume(audioPacket, CustomDiscs.getInstance().musicDiscVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +177,6 @@ public class PlayerManager {
|
|||||||
buffer[i] = 0; // Pad with zero
|
buffer[i] = 0; // Pad with zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(Arrays.toString(buffer));
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user