Repository Public MIT
1# GlassVideoPlayer23| | |4|---|---|5| Identifier | `glass-video-player` |6| Module | `SPGlassMedia` |7| Kind | `native-wrapper` — the system draws the player with AVKit's SwiftUI `VideoPlayer` |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Frameworks | AVKit, AVFoundation |10| Example | `Examples/Gallery/Media/GlassVideoPlayerExample.swift` |1112## Minimal usage1314```swift15GlassVideoPlayer(url: trailerURL)16```1718## Variants1920| Variant | Use |21|---|---|22| `init(url:)` | The view creates and owns an `AVPlayer` for the URL when it appears. |23| `init(player:)` | The host owns the player (shared playback, custom observation, queue players). |24| `aspectRatio:` | Width divided by height, 16:9 by default; `nil` lets the player fill the space it is given. |25| `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:)`. |2627## Parameters2829| Parameter | Type | Default | Meaning |30|---|---|---|---|31| `player` | `AVPlayer?` | — | Player owned by the host; `nil` shows the unavailable state. |32| `url` | `URL?` | — | Local or remote media; `nil` shows the unavailable state. |33| `aspectRatio` | `CGFloat?` | `16/9` | Fitted aspect ratio, clamped to 1:4…4:1; invalid values behave like `nil`. |34| `accessibilityLabel` | `LocalizedStringKey?` | "Video player" | What the video is, for assistive technologies. |3536`GlassVideoControls`3738| Parameter | Type | Default | Meaning |39|---|---|---|---|40| `playback` | `some GlassAudioPlayback` | — | Engine displayed and driven by the controls. |41| `title` | `String?` | `nil` | Shown in a chip at the top; also the accessibility label. |42| `aspectRatio` | `CGFloat?` | `16/9` | Same rule as the player. |43| `skipInterval` | `TimeInterval` | `10` | Seconds skipped by the skip buttons. |44| `surface` | `@ViewBuilder` | — | The picture, clipped to the frame. |4546The 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.4748## States4950- **Available**: the system player with its own controls.51- **Checking**: there is an item whose `isPlayable` is still loading; the player is shown meanwhile.52- **Unavailable**: no player, no current item, or an item that is not playable — a `ContentUnavailableView` with "Media unavailable".5354Playback never starts by itself; the user starts it with the system controls, or the host calls `player.play()`.5556## Advanced example5758```swift59struct LessonView: View {60 @State private var player = AVPlayer(url: lessonURL)6162 var body: some View {63 GlassVideoPlayer(player: player, aspectRatio: 4.0 / 3.0, accessibilityLabel: "Lesson 3")64 .onDisappear { player.pause() }65 }66}67```6869## Accessibility7071- The controls are the system's and keep their own labels, captions menu and keyboard support.72- 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).7374## Limits7576- 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.77- No glass is drawn over or under the player and its shape is not changed.78- 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:)`.79- The repository ships no media file, so the example shows the unavailable states; a real video was not played during verification.80