diff options
| author | ilotterytea <iltsu@alright.party> | 2022-12-10 21:50:26 +0600 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2022-12-10 21:50:26 +0600 |
| commit | aad43ba90df88b06b054e90758ba5f54dd7b66f5 (patch) | |
| tree | 0b3e315284b132fa3e979f7a371f0e4547bdf81c /core | |
| parent | 21a128e69722d7de96c8fb2c6d2c345894751ce2 (diff) | |
Music playlist.
Diffstat (limited to 'core')
| -rw-r--r-- | core/src/com/ilotterytea/maxoning/audio/Playlist.kt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/src/com/ilotterytea/maxoning/audio/Playlist.kt b/core/src/com/ilotterytea/maxoning/audio/Playlist.kt new file mode 100644 index 0000000..32788e6 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/audio/Playlist.kt @@ -0,0 +1,34 @@ +package com.ilotterytea.maxoning.audio + +import com.badlogic.gdx.audio.Music +import com.ilotterytea.maxoning.utils.math.Math + +/** + * Playlist. + */ +class Playlist(vararg musics: Music) { + private val playlist: Array<out Music> = musics + var playingNow: Music = playlist[0] + private var index = 0; + + var shuffleMode = false + + /** + * Play next music. + */ + fun next() { + if (playingNow.isPlaying) playingNow.stop() + + if (shuffleMode) { + index = Math.getRandomNumber(0, playlist.size - 1) + playingNow = playlist[index] + playingNow.play() + } else { + index++ + if (index > playlist.size - 1) index = 0 + + playingNow = playlist[index] + playingNow.play() + } + } +}
\ No newline at end of file |
