Class StandalonePlayer

java.lang.Object
com.vivoka.vsdk.audio.StandalonePlayer

public class StandalonePlayer extends Object
The StandalonePlayer is a simple audio player that allows the user to play audio buffers.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    StandalonePlayer(int sampleRate, int channelCount)
    Constructs a new StandalonePlayer.
    StandalonePlayer(int sampleRate, int channelCount, android.media.AudioAttributes attributes)
    Constructs a new StandalonePlayer with the specified sample rate, channel count, and audio attributes.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Aborts the playback of audio data.
    Gets the current state of the audio player.
    float
    Gets the current volume of the audio player.
    void
    Pauses the playback of audio data.
    void
    process(byte[] audioData)
    Add an audio data chunk to the playback queue.
    void
    process(Buffer buffer)
    Add an audio data chunk to the playback queue.
    void
    process(List<byte[]> source)
    Add a list of audio data chunks to the playback queue.
    void
    Resumes the playback of audio data.
    void
    setOnProgress(androidx.core.util.Consumer<AudioProgress> callback)
    Sets the progress callback for the audio player.
    void
    setOnStateChanged(androidx.core.util.Consumer<StandalonePlayer.State> callback)
    Sets the state change callback for the audio player.
    void
    setVolume(float vol)
    Sets the volume of the audio player.
    void
    Starts the playback of audio data.
    void
    Stops the playback of audio data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • StandalonePlayer

      public StandalonePlayer(int sampleRate, int channelCount)
      Constructs a new StandalonePlayer. The default audio attributes are USAGE_MEDIA and CONTENT_TYPE_SPEECH.
      Parameters:
      sampleRate - The sample rate of the audio data.
      channelCount - The number of channels in the audio data.
    • StandalonePlayer

      public StandalonePlayer(int sampleRate, int channelCount, android.media.AudioAttributes attributes)
      Constructs a new StandalonePlayer with the specified sample rate, channel count, and audio attributes. The audio attributes can be used to customize playback behavior. You can find more details about the audio attributes here: https://developer.android.com/reference/android/media/AudioAttributes
      Parameters:
      sampleRate - The sample rate of the audio.
      channelCount - The number of audio channels.
      attributes - Audio attributes for playback configuration.
  • Method Details

    • start

      public void start()
      Starts the playback of audio data. This method will initialize the player and start the playback thread.
    • process

      public void process(Buffer buffer)
      Add an audio data chunk to the playback queue.
      Parameters:
      buffer - The audio data chunk to process.
    • process

      public void process(byte[] audioData)
      Add an audio data chunk to the playback queue.
      Parameters:
      audioData - The audio data chunk to process.
    • process

      public void process(List<byte[]> source)
      Add a list of audio data chunks to the playback queue.
      Parameters:
      source - The list of audio data chunks to process.
    • pause

      public void pause() throws Exception
      Pauses the playback of audio data.
      Throws:
      Exception - if the audio player fails to pause.
    • resume

      public void resume()
      Resumes the playback of audio data.
    • stop

      public void stop() throws Exception
      Stops the playback of audio data. This method will clear the queue and stop the playback thread.
      Throws:
      Exception - if the audio player fails to stop.
    • abort

      public void abort()
      Aborts the playback of audio data. This method will clear the queue and interrupt the playback thread.
    • setVolume

      public void setVolume(float vol)
      Sets the volume of the audio player.
      Parameters:
      vol - The volume value between 0 and 1.
    • getVolume

      public float getVolume()
      Gets the current volume of the audio player.
      Returns:
      The volume value between 0 and 1.
    • getState

      public StandalonePlayer.State getState()
      Gets the current state of the audio player.
      Returns:
      The current state of the audio player.
    • setOnProgress

      public void setOnProgress(androidx.core.util.Consumer<AudioProgress> callback)
      Sets the progress callback for the audio player. This callback will be invoked when the chunk is sent to the device to be played.
      Parameters:
      callback - The progress callback to set.
    • setOnStateChanged

      public void setOnStateChanged(androidx.core.util.Consumer<StandalonePlayer.State> callback)
      Sets the state change callback for the audio player. This callback will be invoked when the state of the audio player changes.
      Parameters:
      callback - The state change callback to set.