diff options
Diffstat (limited to 'core/src/kz/ilotterytea/maxon/audio')
| -rw-r--r-- | core/src/kz/ilotterytea/maxon/audio/Playlist.kt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/src/kz/ilotterytea/maxon/audio/Playlist.kt b/core/src/kz/ilotterytea/maxon/audio/Playlist.kt new file mode 100644 index 0000000..c1c56cf --- /dev/null +++ b/core/src/kz/ilotterytea/maxon/audio/Playlist.kt @@ -0,0 +1,34 @@ +package kz.ilotterytea.maxon.audio + +import com.badlogic.gdx.audio.Music +import kz.ilotterytea.maxon.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 |
