Docs
Media

Waveform Scrub

A voice note player whose waveform is the scrubber, with a glass time bubble that rides the finger and a playback speed chip.

By · Updated

Waveform Scrub: SwiftUI Audio Waveform Player for iOS, live preview in light mode

Waveform Scrub, a SwiftUI Audio Waveform Player for iOS 17+, in its live preview. Open Code for the Swift source.

$npx swiftpieces add WaveformScrub
See it in a Pro app On a real screen in one of the Pro apps: open it with Pro, take it apart, remix it, and copy the SwiftUI.
Free · MIT + Commons ClauseiOS 17.0+Liquid Glasswaveformaudiovoice-notescrubplaybackspeedmedia
Type
WaveformScrub
Files
WaveformScrub.swift
Depends on
Nothing (Apple frameworks only)
Version
1.0.0

A voice note player whose waveform is the scrubber, for voice messages, audio notes, journals and podcast clips. One liquid glass control: a red play button joined to a glass capsule that holds the waveform and the time, with an optional speed chip joined to its far end. Played bars are inked in the text colour and the rest stay muted, cut exactly at the playhead, mid-bar. Touch the waveform and the playhead drops under the finger, the bars around it rise, and a glass bubble with the time buds up out of the capsule and rides the finger; let go and it melts home and onSeek fires once. A tap seeks too. While a finger is down the time you pass is ignored, so playback updates never fight the scrub, and after the seek the playhead holds where you left it until your player catches up. A vertical drag that starts on the waveform still scrolls an enclosing scroll view. Playback is your app's: the piece never runs a clock of its own. Pass the player's time and isPlaying; between your updates the playhead glides on at the current speed, so a timer that reports a few times a second still draws smooth progress. WaveformScrub.samples(from:count:) reads the peaks of an audio file for samples, off the main thread. swift @State private var player = VoiceNotePlayer(url: note.url) // your AVAudioPlayer wrapper @State private var samples: [Float] = [] WaveformScrub(samples: samples, duration: player.duration, time: player.time, isPlaying: player.isPlaying, rate: $player.rate, onPlayPause: { player.toggle() }, onSeek: { player.seek(to: $0) }) .task { samples = (try? await WaveformScrub.samples(from: note.url)) ?? [] }

Notes

  • One liquid glass control: a red play button joined to a glass capsule that holds the waveform and the time, and, when you pass rate, a smaller speed chip joined to the capsule's far end. Joined parts rest 4 points apart, so short liquid necks hold them together. Red appears only on the play button. On iOS 26 this is Liquid Glass; before that, a frosted material; under Reduce Transparency, solid fills.
  • Playback is your app's. Pass your player's time, duration and isPlaying, start or pause it in onPlayPause, and move it in onSeek. The piece never runs a clock: between your updates the playhead glides on at the current speed for up to a second, so a periodic time observer or a timer that reports a few times a second still draws smooth progress, and a player that stops reporting never runs away.
  • samples are loudness from 0 to 1, any count. They are resampled to the bars that fit the width (3 point bars, 2 points apart by default): the peak of each stretch when there are more samples than bars, smoothly in between when there are fewer. The loudest sample reaches full height and silence is a dot. Played bars are inked in the text colour and the rest stay muted, cut exactly at the playhead, mid-bar.
  • Read samples from an audio file with WaveformScrub.samples(from:count:): it decodes the file in chunks on a background thread (never the main actor), takes the peak of count equal stretches (160 by default) and scales them so the loudest is 1. Cancelling the calling task stops the read. Call it from .task(id: url) and store the result; it throws what AVAudioFile throws for a file it can't open.
  • Touch the waveform and the playhead drops under the finger at once, the bars around it rise, and a glass bubble with the time buds up out of the capsule above the finger on a liquid neck and rides with it. Let go and the bubble melts home and onSeek fires once, with the time in seconds. A tap seeks too. Past either end the playhead stops at the start or the end with a soft tick. While a finger is down the time you pass is ignored, and after the seek the playhead holds where you let go until your time arrives near it (or 1.5 seconds pass), so it never jumps back while your player catches up.
  • The bubble rises about 40 points above the control while a finger is down. Leave that room above it, or let it draw over what's there for that moment; at the very top of a scroll view, the scroll view's edge cuts it.
  • Scrolling is never blocked. Touches come from a UIKit recognizer that begins on a sideways move and fails on a vertical one, and enclosing scroll views, sheets and the back swipe wait for it to fail. Inside a scroll view the press waits about a tenth of a second, so starting a scroll on the waveform never flashes the scrub.
  • States: empty samples (the waveform is loading) shows a quiet row of dots with a soft light passing along them once a second (the dots hold still under Reduce Motion), and seeking still works. A duration of 0 (still unknown) turns seeking off. The time inside the capsule reads the total at the start and the elapsed time otherwise, in 0:42 form, or 1:12:30 from an hour; it keeps the width of the longest time, so the waveform never shifts. When the note has played to its end and stopped there, play turns to replay, and tapping it calls onSeek(0) and then onPlayPause(). Disabled (.disabled(true)), the control greys out, red included, and ignores touches.
  • The speed chip cycles through rates (1×, 1.5× and 2× by default) on each tap, writing the rate binding with a selection tick, and its label morphs letter by letter. It keeps the width of the widest speed, so the waveform never moves, and its target is 44 points tall. Set your player's rate from the binding (AVAudioPlayer.enableRate must be on). Pass no rate for a plain voice note without the chip.
  • Haptics: a light impact on play and pause, a selection tick when a finger grabs the waveform and when the speed changes, a soft tick when a scrub reaches the start or the end.
  • VoiceOver: the play button reads Play, Pause or Play again. The waveform is one adjustable element labelled "Voice note" with a value such as "12 seconds of 42 seconds"; swipe up or down to move 5 seconds through onSeek. The speed chip is a button, "Playback speed", with a value such as "1.5 times" or "Normal". A two-finger double tap plays or pauses from anywhere on the control.
  • Hardware keyboard: with the waveform focused, the arrow keys step 5 seconds (in reading order) and Space plays or pauses.
  • Reduce Motion: the bars don't rise, the bubble fades in and out in place instead of budding, the glyph and digit changes cross-fade, and a seek while paused lands on a short spring with no overshoot.
  • Dynamic Type: the text grows and the shapes follow it part way, up to 1.4 times, so the waveform keeps its room. The time inside the capsule and the speed stop growing at the largest standard size, the bubble at the first accessibility size. All text is one weight, semibold, with monospaced digits.
  • Right to left: play stays on the leading side (now the right), the speed chip moves to the left, the bars play from the right and the time sits on the left of the capsule. The transport glyphs and the speed label are never mirrored.
  • Style sets the play button's red and the glyph on it, the played and unplayed bars, the labels, the control's height (52 points, at least 44) and the bars' width and spacing. Messages replaces the VoiceOver labels, the speed label ("1.5×") and the position value ("12 seconds of 42 seconds"); every default goes through your String Catalog.
  • Wire it to AVAudioPlayer: keep the player in an @Observable model, publish currentTime from a timer or CADisplayLink while playing, call player.currentTime = seconds in onSeek, set player.rate when rate changes, and set isPlaying false in audioPlayerDidFinishPlaying. For AVPlayer, read the time from addPeriodicTimeObserver(forInterval:) and seek with seek(to:toleranceBefore: .zero, toleranceAfter: .zero).

Usage

WaveformScrubExample()

Parameters

ParameterDescription
samplesLoudness from 0 to 1, oldest first, any count: they are resampled to the bars that fit, the peak of each stretch when there are more samples than bars, smoothly in between when there are fewer, and scaled so the loudest reaches full height. Empty while the waveform loads: a quiet row of dots shimmers once a second in its place (they hold still under Reduce Motion), and seeking still works.
durationThe note's length in seconds. Formats the times and maps the waveform to seconds. Zero (still unknown) draws the waveform but turns seeking off.
timeWhere your player is, in seconds. Ignored while a finger is on the waveform. After a seek the playhead holds at the seek until time arrives near it, or 1.5 seconds pass.
isPlayingWhether your player is playing. Swaps play for pause, and lets the playhead glide between your time updates at the current speed.
rateThe playback speed. Shows a speed chip joined to the end of the capsule that cycles through rates on each tap; set your player's rate from it. nil, the default, hides the chip.
ratesThe speeds the chip cycles through, in order. Defaults to 1×, 1.5× and 2×.
messagesThe piece's copy: VoiceOver labels and the speed label. Defaults are localizable through your String Catalog; replace any line, for example title with "Message from Ines".
styleColours, the control's height and the bars' width and spacing. Defaults to the SwiftPieces house palette, adapting to light and dark, with red for the play button.
onPlayPauseCalled when play or pause is tapped (and on Space or a two-finger double tap in VoiceOver). Start or pause your player. When the note has finished (time at duration, not playing), the button shows replay and onSeek(0) is called first.
onSeekCalled once when a scrub or tap ends, for each VoiceOver or arrow key step of 5 seconds, and with 0 before a replay, with the time in seconds to move your player to.

Install

Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.

Terminal

$npx swiftpieces add WaveformScrub

Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected

>Add the SwiftPieces "Waveform Scrub" piece to my app

Or copy the source above into your app.

New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first

Building a whole app? See SwiftPieces Pro →

All media →

Build it yourself: SwiftUI animations guide

On this page

SwiftPiecesPro

Build the whole app with one library.

Production-ready screens, whole flows, complete app templates, a Build Kit your agent follows and Pro remixing.

Explore Pro