Boemo is a software developer who embraces innovative approaches. He likes diving deep into complex concepts in order to learn and write articles that can help the reader understand complex methodologies in a simple and fun way.
The Agora SDK has a play audio feature. You can use this feature to play songs, voice recordings, and sound effects for entertainment or educational purposes during a video call.
In this tutorial, you will learn how to play audio files during a video call using the Agora SDK in Android.
Add the following dependencies in your build.gradle file in the app module, and sync to download the Agora third-party library. Ensure that you always use the latest Agora library version:
Add the following permissions in the Manifest.xml file:
Now, let’s create an RtcEngine instance by initializing the RtcEngine and passing the IRtcEngineEventHandler and your App ID to the create method. IRtcEngineEventHandler is an abstract class that provides the default implementation:
To make the audio file processing fast, you have to load the audio file in advance. The preloadEffect() function takes in the audio ID and the audio file path. This function will load the selected audio file in advance. This function should be called before the user joins the video call:
The playEffect() function plays the audio file passed in the arguments. The playEffect() function takes in the following parameters:
Next, call the playEffect() function to play the audio file in advance:
Agora Android SDK supports only the following audio file types:
You can set the volume percentage of the video call audio by calling the adjustPlaybackSignalVolume() function and passing the volume value/percentage. By default, the video call volume is set to 100. Use this function to adjust the volume of the audio file being played:
The following code fetches the audio file path and plays the audio when the user presses the play button:
Use the stopAudioMixing() function to stop the audio when the stop button is pressed.
The resumeAudioMixing() function resumes the audio being played.
You now know how to play audio files using the Agora SDK methods. The following code block shows you how to integrate the Agora play audio feature in a video streaming application:
If you are not familiar with building a one-to-one video call app using Agora SDK, check this tutorial on GitHub written by Hermes. The above code uses the same concepts taught in that tutorial.
In this tutorial, you have learned how to use the Agora SDK to:
Hooray, you now know how to play audio files during a video call using the Agora SDK!
Thank you for reading. You can learn more on how to play audio using Agora SDK here, and you can check out more Agora features on GitHub here. If you want to copy or reference the SDK I was using, check it on Github here.
If you are getting confused in the process, you can check out Agora’s documentation. You can also join Agora’s Slack channel here.