Class StreamedSoundSource
java.lang.Object
de.pottgames.tuningfork.SoundSource
de.pottgames.tuningfork.jukebox.song.SongSource
de.pottgames.tuningfork.StreamedSoundSource
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
A
SoundSource that streams audio data instead of loading all data at once into memory.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intFields inherited from class SoundSource
sourceId -
Constructor Summary
ConstructorsConstructorDescriptionStreamedSoundSource(com.badlogic.gdx.files.FileHandle file) Creates a newStreamedSoundSourceand loads the first bits of sound data.StreamedSoundSource(AudioStream stream) Creates a newStreamedSoundSourcefrom aAudioStreamand loads the first bits of sound data. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Disposes the sound sources native resources.floatReturns the duration of the attached sound in seconds.floatReturns the current playback position in seconds.
Note that the returned value is subject to small inaccuracies due to the asynchronous nature of this source .booleanisPaused()Returns whether this sound source is paused.booleanReturns whether this sound source is currently playing.voidpause()Pauses the sound playback.voidplay()Starts the playback of this sound source.voidsetLooping(boolean value) Sets wether this sound source should loop.voidsetLoopPoints(float start, float end) Specifies the two offsets the source will use to loop, expressed in seconds.
If the playback position is manually set to something > end, the source will not loop and instead stop playback when it reaches the end of the sound.
The method will throw an exception if start > end or if either is a negative value.voidsetPlaybackPosition(float seconds) Sets the playback position of this sound source.voidstop()Stops the sound playback and rewinds it.Methods inherited from class SoundSource
attachEffect, attachEffect, detachAllEffects, detachEffect, disableAttenuation, enableAttenuation, getAttenuationFactor, getAttenuationMaxDistance, getAttenuationMinDistance, getPitch, getPosition, getRadius, getResampler, getSpatialization, getVirtualization, getVolume, hasFilter, isDirectional, isRelative, makeDirectional, makeOmniDirectional, setAttenuationFactor, setAttenuationMaxDistance, setAttenuationMinDistance, setDirection, setFilter, setPitch, setPosition, setPosition, setRadius, setRelative, setResampler, setResamplerByIndex, setSpatialization, setSpeed, setSpeed, setVirtualization, setVolume
-
Field Details
-
BUFFER_SIZE_PER_CHANNEL
public static final int BUFFER_SIZE_PER_CHANNEL- See Also:
-
BUFFER_COUNT
public static final int BUFFER_COUNT- See Also:
-
-
Constructor Details
-
StreamedSoundSource
public StreamedSoundSource(com.badlogic.gdx.files.FileHandle file) Creates a newStreamedSoundSourceand loads the first bits of sound data.- Parameters:
file- the file
-
StreamedSoundSource
Creates a newStreamedSoundSourcefrom aAudioStreamand loads the first bits of sound data.- Parameters:
stream- the stream
-
-
Method Details
-
getPlaybackPosition
public float getPlaybackPosition()Returns the current playback position in seconds.
Note that the returned value is subject to small inaccuracies due to the asynchronous nature of this source .- Specified by:
getPlaybackPositionin classSongSource- Returns:
- the playback position
-
setLoopPoints
public void setLoopPoints(float start, float end) Specifies the two offsets the source will use to loop, expressed in seconds.
If the playback position is manually set to something > end, the source will not loop and instead stop playback when it reaches the end of the sound.
The method will throw an exception if start > end or if either is a negative value. Values > sound duration are not considered invalid, but they'll be clamped internally.
Setting start and end both to 0, deactivates the loop point mechanic.- Parameters:
start- start position of the loop in secondsend- end position of the loop in seconds
-
setPlaybackPosition
public void setPlaybackPosition(float seconds) Sets the playback position of this sound source. Invalid values are ignored but an error is logged.- Parameters:
seconds- position in seconds
-
setLooping
public void setLooping(boolean value) Description copied from class:SoundSourceSets wether this sound source should loop. When looping is enabled, the source will immediately play the sound again when it's finished playing.- Overrides:
setLoopingin classSoundSource- Parameters:
value- true for looped playback
-
pause
public void pause()Description copied from class:SoundSourcePauses the sound playback.- Overrides:
pausein classSoundSource
-
play
public void play()Description copied from class:SoundSourceStarts the playback of this sound source.- Overrides:
playin classSoundSource
-
stop
public void stop()Description copied from class:SoundSourceStops the sound playback and rewinds it.- Overrides:
stopin classSoundSource
-
isPlaying
public boolean isPlaying()Description copied from class:SoundSourceReturns whether this sound source is currently playing.- Overrides:
isPlayingin classSoundSource- Returns:
- true when this sound source is playing, false otherwise.
-
isPaused
public boolean isPaused()Description copied from class:SoundSourceReturns whether this sound source is paused.- Overrides:
isPausedin classSoundSource- Returns:
- true when this sound source is paused, false otherwise.
-
getDuration
public float getDuration()Returns the duration of the attached sound in seconds.- Specified by:
getDurationin classSongSource- Returns:
- the duration of the attached sound
Returns -1f if the duration couldn't be measured.
-
dispose
public void dispose()Disposes the sound sources native resources. You should never use this sound source after disposing it.- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable- Overrides:
disposein classSoundSource
-