Local WAV Audio Playback
This feature enables your application to play audio from a WAV file stored in your app's raw resources. It is a strict requirement that the WAV file is 48kHz, mono channel with 16-bit audio depth for the audio to be played correctly.
How Does WAV Audio Playback Work
The provided API offers two simple methods:
- Play Audio: Streams and plays a WAV audio file.
- Stop Audio: Stops the currently playing audio.
Make sure that your WAV file complies with the required specifications (48kHz, mono, 16-bit). Placing a non-compliant file may result in playback issues.
How to Stream and Play a WAV File
To start playing a WAV file, add your compliant WAV file to the res/raw folder of your project. Then, use the following API method:
Copy fun streamAndPlayAudioFromRawFile( @androidx.annotation.RawRes audioResourceId: Int, hmsActionResultListener: HMSActionResultListener ) { transportLayer.streamAndPlayAudioFromRawFile(audioResourceId, hmsActionResultListener) }
Below is an example snippet that demonstrates how to call this API:
Copy // Replace R.raw.your_wav_file with the actual WAV file placed in res/raw hmsSDK.streamAndPlayAudioFromRawFile(R.raw.your_wav_file, object : HMSActionResultListener { override fun onSuccess() { // Audio started playing successfully } override fun onError(error: HMSException) { // Handle the error } })
How to Stop the Audio Playback
To stop the audio playback at any time, simply call the following method:
Copy fun stopAudioFromRawFile(hmsActionResultListener: HMSActionResultListener) { transportLayer.stopAudioFromRawFile(hmsActionResultListener) }
Below is a sample snippet demonstrating how to stop the audio playback:
Copy hmsSDK.stopAudioFromRawFile(object : HMSActionResultListener { override fun onSuccess() { // Audio stopped successfully } override fun onError(error: HMSException) { // Handle the error } })
Note: Ensure your WAV file adheres to the strict format of 48kHz, mono channel, 16-bit audio depth. Using files with different specifications might result in unexpected behavior or failure in audio playback.