Class StreamedSoundSource

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable

public class StreamedSoundSource extends SongSource implements com.badlogic.gdx.utils.Disposable
A SoundSource that streams audio data instead of loading all data at once into memory.
  • Field Details

  • Constructor Details

    • StreamedSoundSource

      public StreamedSoundSource(com.badlogic.gdx.files.FileHandle file)
      Creates a new StreamedSoundSource and loads the first bits of sound data.
      Parameters:
      file - the file
    • StreamedSoundSource

      public StreamedSoundSource(AudioStream stream)
      Creates a new StreamedSoundSource from a AudioStream and 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:
      getPlaybackPosition in class SongSource
      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 seconds
      end - 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: SoundSource
      Sets wether this sound source should loop. When looping is enabled, the source will immediately play the sound again when it's finished playing.
      Overrides:
      setLooping in class SoundSource
      Parameters:
      value - true for looped playback
    • pause

      public void pause()
      Description copied from class: SoundSource
      Pauses the sound playback.
      Overrides:
      pause in class SoundSource
    • play

      public void play()
      Description copied from class: SoundSource
      Starts the playback of this sound source.
      Overrides:
      play in class SoundSource
    • stop

      public void stop()
      Description copied from class: SoundSource
      Stops the sound playback and rewinds it.
      Overrides:
      stop in class SoundSource
    • isPlaying

      public boolean isPlaying()
      Description copied from class: SoundSource
      Returns whether this sound source is currently playing.
      Overrides:
      isPlaying in class SoundSource
      Returns:
      true when this sound source is playing, false otherwise.
    • isPaused

      public boolean isPaused()
      Description copied from class: SoundSource
      Returns whether this sound source is paused.
      Overrides:
      isPaused in class SoundSource
      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:
      getDuration in class SongSource
      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:
      dispose in interface com.badlogic.gdx.utils.Disposable
      Overrides:
      dispose in class SoundSource