Skip to content

Commit

Permalink
Add support for different volume implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Aug 30, 2023
1 parent 0943fc6 commit 2c033f0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion music/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subprojects {
version = "3.1.8-SNAPSHOT"
version = "3.1.9-SNAPSHOT"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dev.arbjerg.lavalink.protocol.v4.Track
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.GuildBehavior
import dev.kord.core.entity.channel.VoiceChannel
import dev.schlaubi.lavakord.UnsafeRestApi
import dev.schlaubi.lavakord.audio.Link
import dev.schlaubi.lavakord.audio.TrackEndEvent
import dev.schlaubi.lavakord.audio.TrackStartEvent
Expand Down Expand Up @@ -36,7 +35,7 @@ import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
import kotlin.time.toDuration

private data class SavedTrack(val track: QueuedTrack, val position: Duration, val filters: Filters)
private data class SavedTrack(val track: QueuedTrack, val position: Duration, val filters: Filters, val volume: Int)

class MusicPlayer(val link: Link, private val guild: GuildBehavior) :
Link by link, KordExKoinComponent {
Expand Down Expand Up @@ -204,12 +203,11 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) :

suspend fun injectTrack(identifier: String, noReplace: Boolean = false, playOptionsBuilder: PlayOptions.() -> Unit) = lock.withLock<Unit> {
dontQueue = true
val playOptions = PlayOptions().apply(playOptionsBuilder)
val currentTrack = playingTrack
if (currentTrack != null && !noReplace) {
val currentPosition = player.positionDuration

savedTrack = SavedTrack(currentTrack, currentPosition, player.filters)
savedTrack = SavedTrack(currentTrack, currentPosition, player.filters, player.volume)
}
link.player.searchAndPlayTrack(identifier, playOptionsBuilder)
}
Expand Down Expand Up @@ -248,6 +246,7 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) :
player.playTrack(track.track.track) {
position = track.position
filters = track.filters
volume = track.volume
}
return
}
Expand Down Expand Up @@ -296,6 +295,7 @@ class MusicPlayer(val link: Link, private val guild: GuildBehavior) :
player.playTrack(maybeSavedTrack.track.track) {
position = maybeSavedTrack.position
filters = maybeSavedTrack.filters
volume = maybeSavedTrack.volume
}
return
}
Expand Down

0 comments on commit 2c033f0

Please sign in to comment.