SP GlassKit1.1.0

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.

GlassVideoPlayer 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-video-player

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-video-player
ModuleSPGlassMedia
Kindnative-wrapper — the system draws the player with AVKit's SwiftUI VideoPlayer
PlatformsiOS 26, iPadOS 26, macOS 26
FrameworksAVKit, AVFoundation
ExampleExamples/Gallery/Media/GlassVideoPlayerExample.swift

Minimal usage

Swift
GlassVideoPlayer(url: trailerURL)

Variants

VariantUse
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

ParameterTypeDefaultMeaning
playerAVPlayer?—Player owned by the host; nil shows the unavailable state.
urlURL?—Local or remote media; nil shows the unavailable state.
aspectRatioCGFloat?16/9Fitted aspect ratio, clamped to 1:4…4:1; invalid values behave like nil.
accessibilityLabelLocalizedStringKey?"Video player"What the video is, for assistive technologies.

GlassVideoControls

ParameterTypeDefaultMeaning
playbacksome GlassAudioPlayback—Engine displayed and driven by the controls.
titleString?nilShown in a chip at the top; also the accessibility label.
aspectRatioCGFloat?16/9Same rule as the player.
skipIntervalTimeInterval10Seconds 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 isPlayable is still loading; the player is shown meanwhile.
  • Unavailable: no player, no current item, or an item that is not playable — a ContentUnavailableView with "Media unavailable".

Playback never starts by itself; the user starts it with the system controls, or the host calls player.play().

Advanced example

Swift
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 use init(url:).
  • The repository ships no media file, so the example shows the unavailable states; a real video was not played during verification.

Example

Complete example (compiled with the package)
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

Identifierglass-video-player
Version1.1.0
Depends onglass-audio-player, glass-foundation, glass-media-support
FrameworksSwiftUI, AVKit
Public symbolsGlassVideoControls, GlassVideoControlsVisibility, GlassVideoPlayer, GlassVideoAvailability, GlassVideoLayout
LicenceMIT
Manifestmanifest.json

Files