Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldb09 committed Mar 5, 2023
1 parent dc4138c commit 6f79592
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class WebSocketHandler(
}

val track = decodeTrack(context.audioPlayerManager, json.getString("track"))

if(!track){
return
}
if (json.has("startTime")) {
track.position = json.getLong("startTime")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ class AudioLoaderRestHandler(
HttpStatus.BAD_REQUEST,
"No track to decode provided"
)
val decodedTrack = decodeTrack(audioPlayerManager, trackToDecode).toTrack(trackToDecode)
return ResponseEntity.ok(DecodedTrack(decodedTrack.encoded, decodedTrack.info, decodedTrack.info))
val decodedTrack = decodeTrack(audioPlayerManager, trackToDecode)
if(!decodedTrack) return
val rightOne = decodedTrack.toTrack(trackToDecode)
return ResponseEntity.ok(DecodedTrack(rightOne.encoded, rightOne.info, rightOne.info))
}

@PostMapping(value = ["/decodetracks", "/v3/decodetracks"])
Expand All @@ -86,7 +88,9 @@ class AudioLoaderRestHandler(
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "No tracks to decode provided")
}
return ResponseEntity.ok(encodedTracks.map {
decodeTrack(audioPlayerManager, it).toTrack(it)
val trackE = decodeTrack(audioPlayerManager, it)
if(!trackE) return
val track = trackE.toTrack(it)
})
}

Expand Down
11 changes: 8 additions & 3 deletions protocol/src/main/java/dev/arbjerg/lavalink/protocol/v3/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack
import org.apache.commons.codec.binary.Base64
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import org.slf4j.LoggerFactory
companion object {
private val log = LoggerFactory.getLogger(EventEmitter::class.java)
}


class TrackDecodingException(message: String) : Exception(message)

fun decodeTrack(audioPlayerManager: AudioPlayerManager, message: String): AudioTrack {
fun decodeTrack(audioPlayerManager: AudioPlayerManager, message: String): AudioTrack? {
val bais = ByteArrayInputStream(Base64.decodeBase64(message))
return try {
audioPlayerManager.decodeTrack(MessageInput(bais)).decodedTrack
?: throw TrackDecodingException("Failed to decode track")
?: log.info("Hye bit")
} catch (e: IllegalStateException) {
// Handle the exception here
throw TrackDecodingException("An error occurred while decoding track: ${e.message}")
log.info("Hye bit")
}
}
fun encodeTrack(audioPlayerManager: AudioPlayerManager, track: AudioTrack): String {
Expand Down

0 comments on commit 6f79592

Please sign in to comment.