diff --git a/build.gradle b/build.gradle index 9104747..59ca6ef 100644 --- a/build.gradle +++ b/build.gradle @@ -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}" @@ -60,4 +63,4 @@ shadowJar { classifier 'shadow-dev' //relocate 'javazoom', "me.navoei.${mod_id}.javazoom" //relocate 'org.tritonus', "me.navoei.${mod_id}.tritonus" -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index ecb4d0a..ad4c8a9 100644 --- a/readme.md +++ b/readme.md @@ -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.): diff --git a/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java b/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java index b441142..a341a51 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java +++ b/src/main/java/me/Navoei/customdiscsplugin/PlayerManager.java @@ -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; diff --git a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateCommand.java b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateCommand.java index 84ea3b9..7070783 100644 --- a/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateCommand.java +++ b/src/main/java/me/Navoei/customdiscsplugin/command/SubCommands/CreateCommand.java @@ -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 {