Compose Audio Waveform

263 stars
by Andrew Linc

Audio waveform library for Jetpack Compose

View on GitHub

Documentation

Compose AudioWaveform

GitHub release (latest by date)

GitHub

GitHub followers
GitHub stars
GitHub forks

Description

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.

Waveforms created with AudioWaveform

Download

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}
dependencies {
  implementation 'com.github.lincollincol:compose-audiowaveform:x.y.z'
}

Usage

Common way

var waveformProgress by remember { mutableStateOf(0F) }
AudioWaveform(
  amplitudes = amplitudes,
  progress = waveformProgress,
  onProgressChange = { waveformProgress = it }
)

Custom color

  • SolidColor() - single color Brush.
  • Brush.horizontalGradient(), Brush.verticalGradient() (and more) - default Brush static gradient implementations.
  • Brush.infinite*Gradient() (where * is one of linear, horizontal or vertical) - 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 }
)

All parameters

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 = {}
)

Sample app

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.

Amplituda compatibility

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.

License

   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.
Dispatch Newsletter
Be the first to discover new Compose libraries
Curated Insights
Digest in 5 minutes or less
Android Analysis
Entertaining takes on happenings
Insider Tips
From top Android developers
Hidden Gems
You won't find elsewhere
"
"Dispatch is truly a newsletter, not just a digest of links. Vinay adds a delightful touch of humor and personality to a thoughtful analysis of the Android happenings of the month. I always learn something just by skimming it that makes me want to bookmark the issue now and dig deeper later."
— Zach Klippenstein
ex-Jetpack Compose Team @ Google, Square, Amazon
Join thousands of Android devs who look forward to Dispatch every week