Skip to content

Commit b9b67c7

Browse files
committed
Fixes for reliability of playback and fade-in support.
1 parent f93cd8a commit b9b67c7

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

src/main/kotlin/dev/arbjerg/ukulele/api/PlayerController.kt

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PlayerController(
2222
val botProps: BotProps
2323
) {
2424

25-
25+
private val log = org.slf4j.LoggerFactory.getLogger(PlayerController::class.java)
2626

2727
@GetMapping("/guilds")
2828
fun getGuilds(): List<GuildDto> {
@@ -97,7 +97,7 @@ class PlayerController(
9797
}
9898

9999
var identifiers = (body["url"] ?: "").split("|")
100-
// ... (rest of play method logic)
100+
// ... (rest of play method logic)
101101
if (identifiers.isNotEmpty() && identifiers.first().isEmpty()) {
102102
identifiers = botProps.playlist.split("|")
103103
}
@@ -106,35 +106,43 @@ class PlayerController(
106106

107107
identifiers.forEach { identifier ->
108108
val matcher = pattern.matcher(identifier)
109+
var source = identifier
110+
var queueLabel = ""
109111
if (matcher.find() && matcher.groupCount() == 2) {
110-
// val queueLabel = if (matcher.group(1) != null) matcher.group(1) else ""
111-
val source = if (matcher.group(2) != null) matcher.group(2) else ""
112-
113-
if (source.isNotEmpty()) {
114-
apm.loadItemOrdered(player, source, object : AudioLoadResultHandler {
115-
override fun trackLoaded(track: AudioTrack) {
116-
if (botProps.prependQueueLabelToTitle && matcher.group(1) != null) {
117-
track.info.title = "${matcher.group(1)} - ${track.info.title}"
118-
}
119-
player.add(track)
112+
if (matcher.group(1) != null) queueLabel = matcher.group(1)
113+
if (matcher.group(2) != null) source = matcher.group(2)
114+
} else {
115+
log.warn("Pattern match failed for identifier: '{}', attempting to load as raw URL", identifier)
116+
}
117+
118+
if (source.isNotEmpty()) {
119+
apm.loadItemOrdered(player, source, object : AudioLoadResultHandler {
120+
override fun trackLoaded(track: AudioTrack) {
121+
if (botProps.prependQueueLabelToTitle && queueLabel.isNotEmpty()) {
122+
track.info.title = "$queueLabel - ${track.info.title}"
120123
}
121-
122-
override fun playlistLoaded(playlist: AudioPlaylist) {
123-
if (playlist.isSearchResult) {
124-
val track = playlist.tracks.first()
125-
if (botProps.prependQueueLabelToTitle && matcher.group(1) != null) {
126-
track.info.title = "${matcher.group(1)} - ${track.info.title}"
127-
}
128-
player.add(track)
129-
} else {
130-
player.add(*playlist.tracks.toTypedArray())
124+
player.add(track)
125+
}
126+
127+
override fun playlistLoaded(playlist: AudioPlaylist) {
128+
if (playlist.isSearchResult) {
129+
val track = playlist.tracks.first()
130+
if (botProps.prependQueueLabelToTitle && queueLabel.isNotEmpty()) {
131+
track.info.title = "$queueLabel - ${track.info.title}"
131132
}
133+
player.add(track)
134+
} else {
135+
player.add(*playlist.tracks.toTypedArray())
132136
}
133-
134-
override fun noMatches() {}
135-
override fun loadFailed(exception: FriendlyException) {}
136-
})
137-
}
137+
}
138+
139+
override fun noMatches() {
140+
log.warn("No matches found for source: {}", source)
141+
}
142+
override fun loadFailed(exception: FriendlyException) {
143+
log.error("Load failed for source: {}", source, exception)
144+
}
145+
})
138146
}
139147
}
140148
}

src/main/kotlin/dev/arbjerg/ukulele/audio/Player.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ class Player(private val beans: Beans, guildProperties: GuildProperties) : Audio
197197
// Reset the volume to the current guild volume config
198198
player.volume = scaleVolume(this.volume)
199199

200+
// Only apply queue label volume if the guild volume is not zero.
201+
// This allows the client (e.g. ukulele-remote) to perform a seamless fade-in by
202+
// starting the track at zero volume.
200203
if (this.volume > 0 && (!beans.botProps.normalization || !track.isReplayGainApplied())) {
201204
adjustVolumeFromQueueLabelVolumeMatcher(player, track)
202205
}

0 commit comments

Comments
 (0)