Merge pull request #30 from AMDBartek/main

Implement FLAC file support
This commit is contained in:
Navoei
2023-03-24 10:34:08 -05:00
committed by GitHub
4 changed files with 15 additions and 4 deletions

View File

@@ -28,6 +28,9 @@ dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'org.jflac:jflac-codec:1.5.2'
shadow 'org.jflac:jflac-codec:1.5.2'
// To use this dependency, you need to compile bukkit by yourself
// See https://www.spigotmc.org/wiki/buildtools/
// implementation "org.bukkit:craftbukkit:${bukkit_version}"

View File

@@ -4,7 +4,7 @@ A Paper fork of henkelmax's Audio Player.
- Play custom music discs using the Simple Voice Chat API. (The voice chat mod is required on the client and server.)
- Use ```/customdisc``` or ```/cd``` to create a custom disc.
- Music files should go into ```plugins/CustomDiscs/musicdata/```
- Music files must be in the ```.wav``` or ```.mp3``` format.
- Music files must be in the ```.wav```, ```.flac```, or ```.mp3``` format.
- Only custom discs are compatible with hoppers.
Permission Nodes (Required to run the commands. Playing discs does not require a permission.):

View File

@@ -11,6 +11,8 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.jflac.sound.spi.Flac2PcmAudioInputStream;
import org.jflac.sound.spi.FlacAudioFileReader;
import javax.annotation.Nullable;
import javax.sound.sampled.*;
@@ -121,6 +123,12 @@ public class PlayerManager {
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;

View File

@@ -66,10 +66,10 @@ public class CreateCommand extends SubCommand {
File getDirectory = new File(CustomDiscs.getInstance().getDataFolder(), "musicdata");
File songFile = new File(getDirectory.getPath(), filename);
if (songFile.exists()) {
if (getFileExtension(filename).equals("wav") || getFileExtension(filename).equals("mp3")) {
if (getFileExtension(filename).equals("wav") || getFileExtension(filename).equals("mp3") || getFileExtension(filename).equals("flac")) {
songname = args[1];
} else {
player.sendMessage(ChatColor.RED + "File is not in wav or mp3 format!");
player.sendMessage(ChatColor.RED + "File is not in wav, flac, or mp3 format!");
return;
}
} else {