SPB Git

Repository Public MIT

doc-glass-video-player.md 2.8 KB 67 lines markdown

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. |2526## Parameters2728| Parameter | Type | Default | Meaning |29|---|---|---|---|30| `player` | `AVPlayer?` | — | Player owned by the host; `nil` shows the unavailable state. |31| `url` | `URL?` | — | Local or remote media; `nil` shows the unavailable state. |32| `aspectRatio` | `CGFloat?` | `16/9` | Fitted aspect ratio, clamped to 1:4…4:1; invalid values behave like `nil`. |33| `accessibilityLabel` | `LocalizedStringKey?` | "Video player" | What the video is, for assistive technologies. |3435## States3637- **Available**: the system player with its own controls.38- **Checking**: there is an item whose `isPlayable` is still loading; the player is shown meanwhile.39- **Unavailable**: no player, no current item, or an item that is not playable — a `ContentUnavailableView` with "Media unavailable".4041Playback never starts by itself; the user starts it with the system controls, or the host calls `player.play()`.4243## Advanced example4445```swift46struct LessonView: View {47    @State private var player = AVPlayer(url: lessonURL)4849    var body: some View {50        GlassVideoPlayer(player: player, aspectRatio: 4.0 / 3.0, accessibilityLabel: "Lesson 3")51            .onDisappear { player.pause() }52    }53}54```5556## Accessibility5758- The controls are the system's and keep their own labels, captions menu and keyboard support.59- 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).6061## Limits6263- 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.64- No glass is drawn over or under the player and its shape is not changed.65- 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:)`.66- The repository ships no media file, so the example shows the unavailable states; a real video was not played during verification.67
Files main
Menu

Theme