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