SP GlassKit1.1.0

GlassVolumeControl

Volume of the application's own playback, with mute.

  • System control
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-volume-control

Drawn by the system. GlassKit configures it and leaves the glass to the system.

GlassVolumeControl running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-volume-control

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-volume-control
ModuleSPGlassMedia
Kindnative-wrapper — a plain system button and the system Slider
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Media/GlassVolumeControlExample.swift

Minimal usage

Swift
@State private var volume = 0.8

GlassVolumeControl(volume: $volume)

Variants

VariantUse
DefaultMute button followed by the slider.
unmuteLevel:Level restored by the first unmute when the control starts at 0 (default 0.5).
showsValue: trueThe level as a whole percentage after the slider, in tabular figures.

Parameters

ParameterTypeDefaultMeaning
volumeBinding<Double>—Level of the application's own playback, 0…1. Out-of-range values are clamped.
unmuteLevelDouble0.5Level used by an unmute when no audible level was seen yet.
showsValueBoolfalseShows the percentage after the slider (hidden from assistive technologies, which read the slider's value).

The host applies the level to its player, for example player.volume = Float(volume).

States

  • Audible: the symbol shows one, two or three waves (below 34 %, below 67 %, above).
  • Muted (level 0): slashed speaker; the button's label becomes "Unmute". The level before muting is remembered and restored by unmuting; dragging the slider to 0 keeps the last audible level too.
  • Disabled: the standard .disabled(_:) modifier.

The reducer is GlassVolumeState (togglingMute(), settingLevel(_:)), a value type that can be used without the view.

Advanced example

Swift
struct PlayerVolume: View {
    let player: AVPlayer
    @AppStorage("playbackVolume") private var volume = 0.8

    var body: some View {
        GlassVolumeControl(volume: $volume)
            .frame(maxWidth: 240)
            .onChange(of: volume, initial: true) { _, level in
                player.volume = Float(level)
            }
    }
}

Accessibility

  • The button is labelled "Mute" or "Unmute" (also its tooltip on macOS) and has a 44-point target on iOS.
  • The slider is labelled "Volume"; its value is spoken as a localised percentage, or "Muted" at 0. It is adjustable with VoiceOver.
  • The level is conveyed by the symbol's shape and the spoken value, not by colour.

Limits

  • The control never changes the system volume. On iOS the system volume is only reachable through MPVolumeView, which the host places itself; there is no public API to set it programmatically. On macOS the system volume belongs to the menu bar and the keyboard.
  • The remembered level lives in the view's state: it is lost when the view is destroyed. Persist the level in the host if needed.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassVolumeControlExample: GlassExample {
    public static let componentID = "glass-volume-control"
    @State private var musicVolume = 0.65
    @State private var effectsVolume = 0.0

    public init() {}

    public var body: some View {
        Form {
            Section("Music") {
                GlassVolumeControl(volume: $musicVolume, showsValue: true)
                LabeledContent("Level applied to the player", value: musicVolume, format: .percent.precision(.fractionLength(0)))
            }
            Section("Effects (starts muted)") {
                GlassVolumeControl(volume: $effectsVolume, unmuteLevel: 0.4)
            }
            Section("Disabled") {
                GlassVolumeControl(volume: .constant(0.3))
                    .disabled(true)
            }
        }
        .formStyle(.grouped)
    }
}

#Preview("GlassVolumeControl") { GlassVolumeControlExample().glassTheme(.emerald) }

Registry entry

Identifierglass-volume-control
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassVolumeControl, GlassVolumeState
LicenceMIT
Manifestmanifest.json

Files