Package com.vivoka.vsdk.audio
Class StandalonePlayer
java.lang.Object
com.vivoka.vsdk.audio.StandalonePlayer
The StandalonePlayer is a simple audio player that allows the user to play
audio buffers.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionStandalonePlayer(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 TypeMethodDescriptionvoidabort()Aborts the playback of audio data.getState()Gets the current state of the audio player.floatGets the current volume of the audio player.voidpause()Pauses the playback of audio data.voidprocess(byte[] audioData) Add an audio data chunk to the playback queue.voidAdd an audio data chunk to the playback queue.voidAdd a list of audio data chunks to the playback queue.voidresume()Resumes the playback of audio data.voidsetOnProgress(androidx.core.util.Consumer<AudioProgress> callback) Sets the progress callback for the audio player.voidsetOnStateChanged(androidx.core.util.Consumer<StandalonePlayer.State> callback) Sets the state change callback for the audio player.voidsetVolume(float vol) Sets the volume of the audio player.voidstart()Starts the playback of audio data.voidstop()Stops the playback of audio data.
-
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
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
Add a list of audio data chunks to the playback queue.- Parameters:
source- The list of audio data chunks to process.
-
pause
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
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
Gets the current state of the audio player.- Returns:
- The current state of the audio player.
-
setOnProgress
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
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.
-