Repository Public MIT
1# GlassVolumeControl23| | |4|---|---|5| Identifier | `glass-volume-control` |6| Module | `SPGlassMedia` |7| Kind | `native-wrapper` — a borderless system button and the system `Slider` |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Media/GlassVolumeControlExample.swift` |1011## Minimal usage1213```swift14@State private var volume = 0.81516GlassVolumeControl(volume: $volume)17```1819## Variants2021| Variant | Use |22|---|---|23| Default | Mute button followed by the slider. |24| `unmuteLevel:` | Level restored by the first unmute when the control starts at 0 (default 0.5). |2526## Parameters2728| Parameter | Type | Default | Meaning |29|---|---|---|---|30| `volume` | `Binding<Double>` | — | Level of the application's own playback, 0…1. Out-of-range values are clamped. |31| `unmuteLevel` | `Double` | `0.5` | Level used by an unmute when no audible level was seen yet. |3233The host applies the level to its player, for example `player.volume = Float(volume)`.3435## States3637- **Audible**: the symbol shows one, two or three waves (below 34 %, below 67 %, above).38- **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.39- **Disabled**: the standard `.disabled(_:)` modifier.4041The reducer is `GlassVolumeState` (`togglingMute()`, `settingLevel(_:)`), a value type that can be used without the view.4243## Advanced example4445```swift46struct PlayerVolume: View {47 let player: AVPlayer48 @AppStorage("playbackVolume") private var volume = 0.84950 var body: some View {51 GlassVolumeControl(volume: $volume)52 .frame(maxWidth: 240)53 .onChange(of: volume, initial: true) { _, level in54 player.volume = Float(level)55 }56 }57}58```5960## Accessibility6162- The button is labelled "Mute" or "Unmute" (also its tooltip on macOS) and has a 44-point target on iOS.63- The slider is labelled "Volume"; its value is spoken as a localised percentage, or "Muted" at 0. It is adjustable with VoiceOver.64- The level is conveyed by the symbol's shape and the spoken value, not by colour.6566## Limits6768- 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.69- 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.70