'Stream audio from aws s3 to Discord in java
I am trying to make a discord bot that plays custom sounds, i put the sounds in a aws s3 bucket and i can retrieve them but i dont know how to stream them to discord, i can stream audio files saved locally just fine, to stream local files i use lavaplayer.
This is how i get the file from the s3 bucket:
fullObject = s3Client.getObject(new GetObjectRequest("bucket-name", audioName));
System.out.println("Content-Type: " + fullObject.getObjectMetadata().getContentType());
S3ObjectInputStream s3is = fullObject.getObjectContent();
This i how i play the local files with lavaplayer:
String toPlay = "SoundBoard" + File.separator + event.getArgs();
MessageChannel channel = event.getChannel();
AudioChannel myChannel = event.getMember().getVoiceState().getChannel();
AudioManager audioManager = event.getGuild().getAudioManager();
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
AudioPlayer player = playerManager.createPlayer();
AudioPlayerSendHandler audioPlayerSendHandler = new AudioPlayerSendHandler(player);
audioManager.setSendingHandler(audioPlayerSendHandler);
audioManager.openAudioConnection(myChannel);
TrackScheduler trackScheduler = new TrackScheduler(player);
player.addListener(trackScheduler);
playerManager.registerSourceManager(new LocalAudioSourceManager());
playerManager.loadItem(toPlay, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
trackScheduler.addQueue(track);
}
@Override
public void noMatches() {
channel.sendMessage("audio not found").queue();
trackScheduler.addQueue(null);
}
@Override
public void loadFailed(FriendlyException throwable) {
System.out.println("error " + throwable.getMessage());
}
});
player.playTrack(trackScheduler.getTrack());
So is there a way to stream the files directly with lavaplayer or in another way? (im trying to avoid saving the audio to a file then playing it and then deleting it)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
