GlassVideoPlayer
AVKit video player with system controls and full screen where the platform offers it.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-video-player
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-video-playerCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| Identifier | glass-video-player |
|---|---|
| Module | SPGlassMedia |
| Kind | native-wrapper — the system draws the player with AVKit's SwiftUI VideoPlayer |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Frameworks | AVKit, AVFoundation |
| Example | Examples/Gallery/Media/GlassVideoPlayerExample.swift |
Minimal usage
GlassVideoPlayer(url: trailerURL)Variants
| Variant | Use |
|---|---|
init(url:) | The view creates and owns an AVPlayer for the URL when it appears. |
init(player:) | The host owns the player (shared playback, custom observation, queue players). |
aspectRatio: | Width divided by height, 16:9 by default; nil lets the player fill the space it is given. |
GlassVideoControls(playback:title:) { picture } | Glass transport controls over a picture the host draws (a poster, a custom player layer): play or pause and skip in the centre, a bar with both times and a seek track at the bottom. Driven by any GlassAudioPlayback, for example GlassAVAudioPlayback(player:). |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
player | AVPlayer? | — | Player owned by the host; nil shows the unavailable state. |
url | URL? | — | Local or remote media; nil shows the unavailable state. |
aspectRatio | CGFloat? | 16/9 | Fitted aspect ratio, clamped to 1:4…4:1; invalid values behave like nil. |
accessibilityLabel | LocalizedStringKey? | "Video player" | What the video is, for assistive technologies. |
GlassVideoControls
| Parameter | Type | Default | Meaning |
|---|---|---|---|
playback | some GlassAudioPlayback | — | Engine displayed and driven by the controls. |
title | String? | nil | Shown in a chip at the top; also the accessibility label. |
aspectRatio | CGFloat? | 16/9 | Same rule as the player. |
skipInterval | TimeInterval | 10 | Seconds skipped by the skip buttons. |
surface | @ViewBuilder | — | The picture, clipped to the frame. |
The controls are dark whatever the appearance, as in the system player. While playing they hide after 3 seconds without interaction and a tap on the picture brings them back; they stay visible while paused and while VoiceOver is running (GlassVideoControlsVisibility). When playback.isAvailable is false the "Media unavailable" plate replaces them.
States
- Available: the system player with its own controls.
- Checking: there is an item whose
isPlayableis still loading; the player is shown meanwhile. - Unavailable: no player, no current item, or an item that is not playable — a
ContentUnavailableViewwith "Media unavailable".
Playback never starts by itself; the user starts it with the system controls, or the host calls player.play().
Advanced example
struct LessonView: View {
@State private var player = AVPlayer(url: lessonURL)
var body: some View {
GlassVideoPlayer(player: player, aspectRatio: 4.0 / 3.0, accessibilityLabel: "Lesson 3")
.onDisappear { player.pause() }
}
}Accessibility
- The controls are the system's and keep their own labels, captions menu and keyboard support.
- The player carries the label given by the host; in the unavailable state the label is kept and the value is "Media unavailable" (symbol and text, not colour).
Limits
- Full screen, picture in picture and AirPlay are the platform's own behaviour: iOS offers a full-screen button in the system controls, macOS offers the controls of
AVPlayerView. GlassKit adds no custom full-screen mode. - No glass is drawn over or under the player and its shape is not changed.
- With
init(player:), replacing the player's current item later is not observed by the view; give the view a new identity (.id(item)) or useinit(url:). - The repository ships no media file, so the example shows the unavailable states; a real video was not played during verification.
Example
import SwiftUI
import AVFoundation
import SPGlassKit
public struct GlassVideoPlayerExample: GlassExample {
public static let componentID = "glass-video-player"
/// An empty player: the repository ships no media file, so the example shows the states without a video.
@State private var emptyPlayer = AVPlayer()
/// A silent clock: it drives the glass controls drawn over a poster.
@State private var playback = SampleAudioPlayback(duration: 134)
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
Text("Glass controls over a drawn poster")
.font(.headline)
GlassVideoControls(playback: playback, title: "The Shore House · Trailer") {
SampleArtwork(3)
}
Text("No player")
.font(.headline)
GlassVideoPlayer(player: nil, accessibilityLabel: "Trailer")
Text("Player without an item, 4:3")
.font(.headline)
GlassVideoPlayer(player: emptyPlayer, aspectRatio: 4.0 / 3.0, accessibilityLabel: "Lecture recording")
Text("Missing URL")
.font(.headline)
GlassVideoPlayer(url: nil)
Text("Sample data · give the player a real URL to see the system controls.")
.font(.caption)
.foregroundStyle(.secondary)
}
.padding()
}
.task(id: playback.isPlaying) {
// The fake engine has no clock of its own: tick it while it is "playing".
while playback.isPlaying, !Task.isCancelled {
try? await Task.sleep(for: .milliseconds(500))
if !Task.isCancelled { playback.advance(by: 0.5) }
}
}
}
}
#Preview("GlassVideoPlayer") { GlassVideoPlayerExample().glassTheme(.obsidian) }
Registry entry
| Identifier | glass-video-player |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-audio-player, glass-foundation, glass-media-support |
| Frameworks | SwiftUI, AVKit |
| Public symbols | GlassVideoControls, GlassVideoControlsVisibility, GlassVideoPlayer, GlassVideoAvailability, GlassVideoLayout |
| Licence | MIT |
| Manifest | manifest.json |
Files
Media/Media/GlassVideoPlayer+Controls.swift12514 bytes · sha256 77a891fc6bcf…Media/Media/GlassVideoPlayer.swift6328 bytes · sha256 2ca85909ad95…