|
| 1 | +import com.dunctebot.sourcemanagers.elgato.streamdeck.StreamDeckAudioSourceManager; |
| 2 | +import com.sedmelluq.discord.lavaplayer.format.AudioDataFormat; |
| 3 | +import com.sedmelluq.discord.lavaplayer.format.AudioPlayerInputStream; |
| 4 | +import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; |
| 5 | +import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; |
| 6 | +import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; |
| 7 | +import com.sedmelluq.discord.lavaplayer.player.FunctionalResultHandler; |
| 8 | + |
| 9 | +import javax.sound.sampled.AudioInputStream; |
| 10 | +import javax.sound.sampled.AudioSystem; |
| 11 | +import javax.sound.sampled.DataLine; |
| 12 | +import javax.sound.sampled.SourceDataLine; |
| 13 | + |
| 14 | +import static com.sedmelluq.discord.lavaplayer.format.StandardAudioDataFormats.COMMON_PCM_S16_BE; |
| 15 | + |
| 16 | +public class LocalPlaybackTest { |
| 17 | + public static void main(String[] args) throws Exception { |
| 18 | + final var mngr = new StreamDeckAudioSourceManager(); |
| 19 | + |
| 20 | + AudioPlayerManager manager = new DefaultAudioPlayerManager(); |
| 21 | + |
| 22 | + manager.registerSourceManager(mngr); |
| 23 | + |
| 24 | + manager.getConfiguration().setOutputFormat(COMMON_PCM_S16_BE); |
| 25 | + |
| 26 | + AudioPlayer player = manager.createPlayer(); |
| 27 | + |
| 28 | + player.setVolume(35); |
| 29 | + |
| 30 | + manager.loadItem( |
| 31 | + "https://cdn.discordapp.com/attachments/340834322674089986/1242398908815118376/Fanfare_-_Show_Intro.streamDeckAudio?ex=664f0326&is=664db1a6&hm=9a4898f7301601b3bc14cfda4101aab0ed94cdfb5fe89d2a0917dc4e01514da6&", |
| 32 | + new FunctionalResultHandler(item -> { |
| 33 | + player.playTrack(item); |
| 34 | + }, playlist -> { |
| 35 | + player.playTrack(playlist.getTracks().get(0)); |
| 36 | + }, null, null) |
| 37 | + ); |
| 38 | + |
| 39 | + |
| 40 | + AudioDataFormat format = manager.getConfiguration().getOutputFormat(); |
| 41 | + AudioInputStream stream = AudioPlayerInputStream.createStream(player, format, 10000L, false); |
| 42 | + SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, stream.getFormat()); |
| 43 | + SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); |
| 44 | + |
| 45 | + line.open(stream.getFormat()); |
| 46 | + line.start(); |
| 47 | + |
| 48 | + byte[] buffer = new byte[COMMON_PCM_S16_BE.maximumChunkSize()]; |
| 49 | + int chunkSize; |
| 50 | + |
| 51 | + while ((chunkSize = stream.read(buffer)) >= 0) { |
| 52 | + line.write(buffer, 0, chunkSize); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments