[Huawei Developers] Sherlock F:
More information like this, you can visit HUAWEI Developer Forum​

Introduction:

HUAWEI Audio Kit provides a set of audio capabilities based on the HMS Core ecosystem, including audio encoding and decoding capabilities at the hardware level and system bottom layer. It provides developers with convenient, efficient, and rich audio services.

Audio Kit provides developers with the ability to parse and play multiple audio formats such as m4a / aac / amr / flac / imy / wav / ogg / rtttl / mp3. It can provide cache capabilty and support customizig the size of the cache space.

Prerequisites:

Java JDK (JDK 1.7 is recommended.)

Android Studio 3.X

SDK Platform 19 or later

Gradle 4.6 or later

HMS Core (APK) 5.0.0.300 or later

Integration:

1. Create a project in android studio and Huawei AGC.

2. Provide the SHA-256 Key in App Information Section.

3. Download the agconnect-services.json from AGCand save into app directory.

4. In root build.gradle

Navigate to allprojects > repositories and buildscript > repositories and add the given line.

maven { url 'http://developer.huawei.com/repo/' }

5. In app build.gradle

Configure the Maven dependency

implementation 'com.huawei.hms:audiokit-player:1.0.0.302'

6. Permissions in Manifest

<!-- Need to access the network and obtain network status information-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- android4.4 To operate SD card, you need to apply for the following permissions -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_STORAGE" />

<!-- 9.0 Adaptation -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<!-- Play songs to prevent CPU from sleeping. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

Code Implementation:

Here is an Audio application which is using HMS Audio Kit features. The application gives an excellent audio experience with audio streaming from a third-party cloud platform. The application listing song details with a name and duration. User can select the track from the list and can listen the music. The application uses recycleview and cardview libraries apart from HMS Audio Kit library.

1. Create an audio management instance by calling HwAudioManager; manage audio playback by calling HwAudioPlayerManager; manage audio queues by calling HwAudioQueueManager;manage audio configurations by calling HwAudioConfigManager.

public void init(final Context context) {
Log.i(TAG, "init start");
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
HwAudioPlayerConfig hwAudioPlayerConfig = new HwAudioPlayerConfig(context);
HwAudioManagerFactory.createHwAudioManager(hwAudioPlayerConfig, new HwAudioConfigCallBack() {
@Override
public void onSuccess(HwAudioManager hwAudioManager) {
try {
Log.i(TAG, "createHwAudioManager onSuccess");
mHwAudioManager = hwAudioManager;
mHwAudioPlayerManager = hwAudioManager.getPlayerManager();
mHwAudioQueueManager = hwAudioManager.getQueueManager();
mHwAudioConfigManager = hwAudioManager.getConfigManager();
} catch (Exception e) {
Log.e(TAG, "init fail", e);
}
}

@Override
public void onError(int errorCode) {
Log.e(TAG, "init error:" + errorCode);
}
});
return null;
}
}.execute();
}

2. Create a Playlist. Here using ArrayList

public List<HwAudioPlayItem> getAudioList() {
List<HwAudioPlayItem> playItemList = new ArrayList<>();
for (int i=0;i<MyData.nameArray.length;i++) {
HwAudioPlayItem audioPlayItem = new HwAudioPlayItem();
audioPlayItem.setAudioId(""+i+1);
audioPlayItem.setSinger("K.J Yesudas");
audioPlayItem.setOnlinePath(MyData.AudiorlArray[i]);
audioPlayItem.setOnline(1);
audioPlayItem.setAudioTitle(MyData.nameArray[i]);
playItemList.add(audioPlayItem);
}

return playItemList;
}

3. Play Audio

HwAudioPlayerManager.play();

4. Pause Audio

mHwAudioPlayerManager.pause();

5. For Next track

mHwAudioPlayerManager.playNext();

6. For previous track

mHwAudioPlayerManager.playPre();

7. Select a track from recycleview

@Override
public void onItemClick(int pos) {
if (mHwAudioPlayerManager != null) {
mHwAudioPlayerManager.play(pos);
}
}

8. Stop Audio

mHwAudioPlayerManager.stop();

Screen Shots:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20200921075215.42203946339158936796154618772697:50510927085115:2800:E4A6BDB3A3E7001764FAD7359777591FAB3C03348B1BEF5273B3C6E87FE71C6D.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20200921075215.42203946339158936796154618772697:50510927085115:2800:E4A6BDB3A3E7001764FAD7359777591FAB3C03348B1BEF5273B3C6E87FE71C6D.jpg[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20200921081834.60666581062782594695998735578016:50510927085115:2800:8E7943A8F67722B8724D6C091F26574746F49983559E9055B3F1AB7C7C1EA686.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/745/226/2640091000001745226.20200921081834.60666581062782594695998735578016:50510927085115:2800:8E7943A8F67722B8724D6C091F26574746F49983559E9055B3F1AB7C7C1EA686.png[/IMG]

Conclusion:-

Audio Kit provides an excellent experience in Audio playback. It allows developers to quickly build their own local or online playback applications. It can provide a better hearing effects based on the multiple audio effects capabilities. It provides a variety of playback control operation methods to facilitate developers to control application operations.

Reference:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050749665