AudioWaveform is a lightweight Jetpack Compose library which draws waveform of audio.
Library uses compose Canvas API
under the hood. It helps us to create customizable and flexible waveforms.
This library was inspired by the WaveformSeekBar library (xml
implementation).
AudioWaveform is fully compatible with Amplituda library.
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.lincollincol:compose-audiowaveform:x.y.z'
}
var waveformProgress by remember { mutableStateOf(0F) }
AudioWaveform(
amplitudes = amplitudes,
progress = waveformProgress,
onProgressChange = { waveformProgress = it }
)
SolidColor()
- single colorBrush
.Brush.horizontalGradient()
,Brush.verticalGradient()
(and more) - defaultBrush
static gradient implementations.Brush.infinite*Gradient()
(where * is one oflinear
,horizontal
orvertical
) - infinite animated gradient. This is AudioWaveform library extension functions created with this article.
var waveformProgress by remember { mutableStateOf(0F) }
val colorBrush = SolidColor(Color.Magenta)
val staticGradientBrush = Brush.linearGradient(colors = listOf(Color(0xff22c1c3), Color(0xfffdbb2d)))
val animatedGradientBrush = Brush.infiniteLinearGradient(
colors = listOf(Color(0xff22c1c3), Color(0xfffdbb2d)),
animation = tween(durationMillis = 6000, easing = LinearEasing),
width = 128F
)
AudioWaveform(
progress = waveformProgress,
progressBrush = brush,
amplitudes = amplitudes,
onProgressChange = { waveformProgress = it }
)
var waveformProgress by remember { mutableStateOf(0F) }
AudioWaveform(
modifier = Modifier.fillMaxWidth(),
// Spike DrawStyle: Fill or Stroke
style = Fill,
waveformAlignment = WaveformAlignment.Center,
amplitudeType = AmplitudeType.Avg,
// Colors could be updated with Brush API
progressBrush = SolidColor(Color.Magenta),
waveformBrush = SolidColor(Color.LightGray),
spikeWidth = 4.dp,
spikePadding = 2.dp,
spikeRadius = 4.dp,
progress = waveformProgress,
amplitudes = amplitudes,
onProgressChange = { waveformProgress = it },
onProgressChangeFinished = {}
)
You could also try sample app, which demonstrates all AudioWaveform library features.
Waveform from sample app is also synchronized with Media3.
Download sample app apk here.
AudioWaveform requires amplitudes
to draw waveform. This parameter is a list of integers, which represents audio data.
You can process the audio file by yourself or use already existing library Amplituda.
Amplituda is a fast audio processing library, which provides you data for drawing waveforms.
Library has caching and compressing processed data features out of the box.
Here is Amplituda library usage in a sample app.
Copyright 2022-present lincollincol
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.