Class JukeBox
java.lang.Object
de.pottgames.tuningfork.jukebox.JukeBox
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PlayListprotected Songprotected com.badlogic.gdx.utils.Array<JukeBoxEvent> protected com.badlogic.gdx.utils.Pool<JukeBoxEvent> protected final com.badlogic.gdx.utils.Array<JukeBoxObserver> protected final PlayListProviderprotected booleanprotected com.badlogic.gdx.math.Interpolationprotected floatprotected floatprotected longprotected booleanprotected float -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObserver(JukeBoxObserver observer) Adds an observer.voidclear()Immediately stops playback, removes all observers and sets theJukeBoxinto a stopped state.protected floatdetermineFadeVolume(SongSource source, SongSettings settings) protected floatfadeIn(SongSource source, SongSettings settings, float playbackPos) protected floatfadeOut(SongSource source, SongSettings settings, float playbackPos, float songDuration) Returns theSongthat is currently playing.floatReturns the JukeBox's master volume.
The final volume equation looks like:
master volume = JukeBox.getVolume() * SongSettings.fadeVolume()protected voidbooleanReturns true if thisJukeBoxis playing at the moment.protected voidnextSong()protected voidprotected voidprotected voidprotected voidnotifyPlayListEnd(PlayList playList) protected voidnotifyPlayListStart(PlayList playList) protected voidnotifySongEnd(Song song) protected voidnotifySongStart(Song song) voidpause()Pauses playback.voidplay()Starts playback.protected voidprotected voidpushEvent(JukeBoxEvent.JukeBoxEventType type, PlayList playList) protected voidpushEvent(JukeBoxEvent.JukeBoxEventType type, Song song) voidremoveObserver(JukeBoxObserver observer) Removes an observer.protected voidresetSoftStop(boolean clearResume) voidsetVolume(float volume) Sets the master volume of the Jukebox.
The change isn't applied immediately, it will be applied in the next call toupdate().
The final volume equation looks like:
master volume = JukeBox.getVolume() * SongSettings.fadeVolume()booleansoftStop(com.badlogic.gdx.math.Interpolation fadeOutCurve, float fadeOutDuration) voidsoftStopAndResume(com.badlogic.gdx.math.Interpolation fadeOutCurve, float fadeOutDuration) Soft stops (seesoftStop(Interpolation, float)), ends the currentPlayListand resumes playback afterward if possible.
Since it may not be clear at first glance what the use cases are, here is an example:
The World-PlayList is running, but the player gets ambushed, whereupon the World-PlayList should fade-out and the Danger-PlayList should begin playing.
This is achievable in 2 steps:
1.protected voidsoftStopFade(SongSource source) voidstop()Stops playback and resets the currentPlayListif applicable.voidupdate()Updates the JukeBox.
-
Field Details
-
observer
-
currentPlayList
-
playListProvider
-
currentSong
-
stopped
protected boolean stopped -
volume
protected float volume -
softStop
protected boolean softStop -
softStopStartTime
protected long softStopStartTime -
softStopFadeDuration
protected float softStopFadeDuration -
softStopFadeCurve
protected com.badlogic.gdx.math.Interpolation softStopFadeCurve -
softStopFadeStartVolume
protected float softStopFadeStartVolume -
eventPool
-
eventHistory
-
-
Constructor Details
-
JukeBox
Creates a new JukeBox.- Parameters:
playListProvider- the playlist provider
-
-
Method Details
-
update
public void update()Updates the JukeBox. This method should be called every frame. -
softStopFade
-
determineFadeVolume
-
fadeIn
-
fadeOut
protected float fadeOut(SongSource source, SongSettings settings, float playbackPos, float songDuration) -
setVolume
public void setVolume(float volume) Sets the master volume of the Jukebox.
The change isn't applied immediately, it will be applied in the next call toupdate().
The final volume equation looks like:
master volume = JukeBox.getVolume() * SongSettings.fadeVolume()- Parameters:
volume- in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume, values outside of the range will be clamped
-
getVolume
public float getVolume()Returns the JukeBox's master volume.
The final volume equation looks like:
master volume = JukeBox.getVolume() * SongSettings.fadeVolume()- Returns:
- the master volume in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume
-
play
public void play()Starts playback. -
pause
public void pause()Pauses playback. Callingplay()will resume playback. -
stop
public void stop()Stops playback and resets the currentPlayListif applicable. -
resetSoftStop
protected void resetSoftStop(boolean clearResume) -
softStop
public boolean softStop(com.badlogic.gdx.math.Interpolation fadeOutCurve, float fadeOutDuration) Fades out the currently playing song and stops theJukeBoxafterwards.
There's a couple of reasons why theJukeBoxmight stop early:
- the rest of the song is shorter than the desired fadeOutDuration
- the song duration is not available
- fadeOutCurve is null
- fadeOutDuration is smaller or equal 0- Parameters:
fadeOutCurve- the interpolation used to fade-outfadeOutDuration- fade out duration in seconds- Returns:
- false if a soft stop couldn't be performed and it is stopped right away
-
softStopAndResume
public void softStopAndResume(com.badlogic.gdx.math.Interpolation fadeOutCurve, float fadeOutDuration) Soft stops (seesoftStop(Interpolation, float)), ends the currentPlayListand resumes playback afterward if possible.
Since it may not be clear at first glance what the use cases are, here is an example:
The World-PlayList is running, but the player gets ambushed, whereupon the World-PlayList should fade-out and the Danger-PlayList should begin playing.
This is achievable in 2 steps:
1. change the theme in ThemePlayListProviderThemePlayListProvider.setTheme(int)
2. call softStopAndResume on the JukeBox- Parameters:
fadeOutCurve- the interpolation used to fade-outfadeOutDuration- the fade-out duration in seconds
-
clear
public void clear()Immediately stops playback, removes all observers and sets theJukeBoxinto a stopped state. -
getCurrentSong
-
isPlaying
public boolean isPlaying()Returns true if thisJukeBoxis playing at the moment.- Returns:
- true if playing
-
nextSong
protected void nextSong() -
addObserver
Adds an observer. SeeJukeBoxObserverfor details.- Parameters:
observer- the jukebox observer
-
removeObserver
Removes an observer.- Parameters:
observer- the jukebox observer
-
pushEvent
-
pushEvent
-
pushEvent
-
handleEvents
protected void handleEvents() -
notifySongStart
-
notifySongEnd
-
notifyPlayListStart
-
notifyPlayListEnd
-
notifyJukeBoxEnd
protected void notifyJukeBoxEnd() -
notifyJukeBoxStart
protected void notifyJukeBoxStart() -
notifyJukeBoxPause
protected void notifyJukeBoxPause()
-