How to Build Audio Environment of Android App with Audio Kit of HMS Core — 1
Hello everyone,
In this article, I want to talk about Audio Kit of HMS Core, its implementation and place of use.
First of all, what is Audio Kit?
Audio kit is a set of audio capabilities developed by Huawei. We can do almost everything about audio by the features which audio kit provides.
Kit focuses on audio playback, audio effects and audio data mainly. We can build a nice audio environment for our app with it.
It allows the app to play audio, control playback, adjust volume I mean increase and decrease of it, manage playlists, manage play modes, saving playback progress, cache and encrypt audio content. It also supports 4 different play modes; sequential, repeating a song, repeating playlist and shuffling playlist.
Even if the application is only music based, Audio Kit has solution for all needing.
Important: Audio Kit is free of charge.
Implementation: Getting Started
You can check official guide for preparations of the kit development: https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/dev-process-0000001051069604
For the audio operations, we will have a helper class which name is Audio Helper in my project. This class will be used to avoid repetitions of code.
Regardless of the need, first step is creating audio management instance in a custom initialization method:
HwAudioManager class is the main class that should be initialized first in the application. So, we should call initialization in our application class.
HwAudioPlayerManager class which is taken from HwAudioManager give us playback management operations. Here is the list of these operations. So, we are adding these method into our helper class with a little customize according to needing.
HwAudioQueueManager which is taken from HwAudioManager give us queue management operations. Playlist changes are handled in this class like setting playlist, adding/removing list of audio on playlist. So I am adding methods I will use to helper class again.
Other class that we take from HwAudioManager is HwAudioConfigManager. This class provides us setting the cache size, clearing the cache, and saving the playlist.
To create a playlist with online audios, audios from resource and local audios, we should have a custom method which returns the list of HwAudioPlayItem. For this, I recommend you to read this article[HUAWEI Audio Kit [read audio file from resources folder, online URL and local path]] from Huawei forums.
Now, I will not share to exact code where I fill a playlist and set it into HwAudioPlayerManager. But you can implement the function in the article above.
By the way, to change the play mode by the function “setPlayMode” we wrote in AudioHelper class. This method parameter is integer which represent the mode. 0 for sequential playback, 1 for shuffling songs, 2 for repeating a playlist, 3 for repeating a song. Default value is 0.
In this article, we built an audio environment and methods we need. In next article, we are going to add some effect on Audio items. You can check details of audio effect improvement in kit which is added with 1.3.0.300 version in offical guide.
Thanks for reading. If you have question, please feel free to contact me by writing comment!
References
Huawei AudioKit Official Guide: https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/form-recognition-0000001058920154
Extensive Tutorial series with Audio Kit: https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/service-introduction-0000001050040017