Skip to main content
VESDK/Android/Guides/Audio Overlays

Custom Audio

VideoEditor SDK for Android allows showing a custom fragment for audio selection

Custom audio fragment#

The CustomAudioFragment class is part of the VideoEditor SDK for Android and is used to specify a custom fragment for audio selection. This can be done by creating a CustomAudioTrackCategoryItem and specifying a subclass of CustomAudioFragment to be added to the view hierarchy when the category is selected.

To add an audio track to the video, call the CustomAudioFragment.selectAudio(track: AudioTrackAsset?, autoPlayTrack: Boolean = true) method. If the audio track should be embedded in the serialization, an AssetResolver should be added to the AudioTrackAsset, as shown in the example below:

AudioTrackAsset.createTemporaryAsset(
id = assetId,
resolver = SoundstripeProxyAssetResolver(song.id),
audioSource = AudioSource.create(UriHelper.convertToLocalUri(Uri.parse(songUri))),
title = song.attributes?.title,
artist = (song.relationships?.artists?.data?.attributes?.name,
durationInSeconds = audioFile.attributes?.duration?.roundToInt() ?: -1
)

Custom fragments that extend the CustomAudioFragment are responsible for the audio playback and management within their own UI.

The sound preview of the selected audio track can be controlled by setting the audioPlayState to PlayState.PLAY, PlayState.PAUSED, or PlayState.STOPPED``. The selected audio can be accessed in UiStateAudio and can be used to select/highlight the selected audio item when the fragment is created.

In your custom fragment, you must also respect any pause requests made by the main list of audio files or other custom fragments. You can do this by implementing the onPauseRequested method. When a pause request is received, you have to update your UI to the paused state.

override fun onPauseRequested() {
// your implementation to handle pause request of other categories
}

You must also respect any release selection requests made by the main list of audio files or other custom fragments. You can do this by implementing the onReleaseSelectionRequested method. When a release selection request is received, you must update the UI to the unselected state.

override fun onReleaseSelectionRequested() {
// your implementation to handle release selection request, when another category select an audio file.
}

Finally, when the audio panel is fully closed, the onAudioPanelClosed method will be called. This method is not called during configuration changes, so it is the best point to release any resources associated with the current audio session.

override fun onAudioPanelClosed() {
// your implementation to handle audio panel is close
}

To pause audio playback, you can call the requestPause method. This will tell other custom fragments and the main list of audio files to pause their players and update the UI to the paused state.

requestPause()