sedmelluq / lavaplayer

Audio player library for Discord
Apache License 2.0
966 stars 247 forks source link

transfering a AudioTrack object #88

Closed FlashOnFire closed 6 years ago

FlashOnFire commented 6 years ago

Hello, I want to transfer a AudioTrack with an RMI setup but the object AudioTrack isn't Serializable. Can you make it implements Serializable please ?

freyacodes commented 6 years ago

Take a look at this

    public static AudioTrack toAudioTrack(String message) throws IOException {
        byte[] b64 = Base64.decodeBase64(message);
        ByteArrayInputStream bais = new ByteArrayInputStream(b64);
        return Player.PLAYER_MANAGER.decodeTrack(new MessageInput(bais)).decodedTrack;
    }

    public static String toMessage(AudioTrack track) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Player.PLAYER_MANAGER.encodeTrack(new MessageOutput(baos), track);
        return Base64.encodeBase64String(baos.toByteArray());
    }

From https://github.com/Frederikam/Lavalink/blob/master/LavalinkServer/src/main/java/lavalink/server/util/Util.java#L41-L51

FlashOnFire commented 6 years ago

Thanks, I'll give it a try now

FlashOnFire commented 6 years ago

It works, thanks a lot @Frederikam !

freyacodes commented 6 years ago

:+1:

FlashOnFire commented 6 years ago

Hi,

I have a similar issue because with this kind of transfer, I can't play some mp3 files. Here's the stack trace :

[lava-daemon-pool-playback-1-thread-10] ERROR com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor - Error in playback of C:\Users\FlashOnFire\Desktop\JingleEmission.mp3
com.sedmelluq.discord.lavaplayer.tools.FriendlyException: Something broke when playing the track.
        at com.sedmelluq.discord.lavaplayer.tools.ExceptionTools.wrapUnfriendlyExceptions(ExceptionTools.java:40)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.execute(LocalAudioTrackExecutor.java:102)
        at com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager.lambda$executeTrack$1(DefaultAudioPlayerManager.java:348)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\FlashOnFire\Desktop\JingleEmission.mp3 (No such file or directory)
        at com.sedmelluq.discord.lavaplayer.source.local.LocalSeekableInputStream.<init>(LocalSeekableInputStream.java:36)
        at com.sedmelluq.discord.lavaplayer.source.local.LocalAudioTrack.process(LocalAudioTrack.java:43)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.execute(LocalAudioTrackExecutor.java:90)
        ... 4 more
Caused by: java.io.FileNotFoundException: C:\Users\FlashOnFire\Desktop\JingleEmission.mp3 (No such file or directory)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at com.sedmelluq.discord.lavaplayer.source.local.LocalSeekableInputStream.<init>(LocalSeekableInputStream.java:32)
        ... 6 more
com.sedmelluq.discord.lavaplayer.tools.FriendlyException: Something broke when playing the track.
        at com.sedmelluq.discord.lavaplayer.tools.ExceptionTools.wrapUnfriendlyExceptions(ExceptionTools.java:40)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.execute(LocalAudioTrackExecutor.java:102)
        at com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager.lambda$executeTrack$1(DefaultAudioPlayerManager.java:348)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\FlashOnFire\Desktop\JingleEmission.mp3 (No such file or directory)
        at com.sedmelluq.discord.lavaplayer.source.local.LocalSeekableInputStream.<init>(LocalSeekableInputStream.java:36)
        at com.sedmelluq.discord.lavaplayer.source.local.LocalAudioTrack.process(LocalAudioTrack.java:43)
        at com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor.execute(LocalAudioTrackExecutor.java:90)
        ... 4 more
sedmelluq commented 6 years ago

The machine you're trying to play it on doesn't have that file at that location. The serialized AudioTrack doesn't contain the file itself.

FlashOnFire commented 6 years ago

How can I do then ?

sedmelluq commented 6 years ago

Plenty of ways:

This is not really related to Lavaplayer anymore since it is not meant to be and will not be an implementation of rysnc.

FlashOnFire commented 6 years ago

Okay, thanks for your help !