VideoKit is a SwiftUI library with a configurable VideoPlayer view, and other utilities like a VideoSplashScreen, views, sample data and Chromecast support.
Unlike AVKit's VideoPlayer, VideoKit's VideoPlayer can be configured to great extent. It also lets you observe the current player time and can trigger a custom action when the player reaches the end.
Installation
VideoKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/VideoKit.git
Important
For remote video playback to work in macOS Catalyst, you must enable "Outgoing Connections (Client)" under "Signing & Capabilities > App Sandbox" and enable "App Transport Security Settings > Allow Arbitrary Loads" (for more security, specify allowed domains) under the app's "Info" configuration.
Supported Platforms
VideoKit supports iOS 15, iPadOS 15, macOS Catalyst 15, tvOS 15, and visionOS 1.
Features
VideoKit supports a bunch of video-related features:
- 🎬 Video Player - A custom video player view.
- ✨ Video Splash Screen - A video-based splash screen that plays when your app launches.
- 🖼️ Views - A bunch of video-related views and modifiers.
- 🗞️ Pagination - Built-in pagination support.
- 🍬 Sample Data - Free samples to use while developing.
VideoKit also includes Chromecast support:
- 📽️ Chromecast SDK - Google Cast dependency.
See the documentation for more information.
Getting Started
To add video content to your app, just add a VideoPlayer with a URL to the content you want to play:
struct ContentView: View { @State var videoTime = TimeInterval.zero var body: some View { VideoPlayer( videoURL: VideoPlayer.sampleVideoURL, time: $videoTime, configuration: .init(autoPlay: false), controllerConfiguration: { controller in controller.showsPlaybackControls = false }, didPlayToEndAction: { print("The end") } ) .aspectRatio(16/9, contentMode: .fit) } }
You can inject a time binding which lets you persist the player time and resume playback, inject custom player and controller configurations, and a didPlayToEndAction to trigger when playback ends.
To add video splash screen, just apply a .videoSplashScreen(videoURL:configuration:) to your root view:
struct ContentView: View { var body: some View { Text("Hello, world") .videoSplashScreen( videoURL: VideoPlayer.sampleVideoURL, configuration: .init( dismissAnimation: .linear(duration: 2), maxDisplayDuration: 2 ), videoPlayerView: { videoPlayer in Color.red videoPlayer.aspectRatio(contentMode: .fit) } ) } }
You can pass in a configuration to customize the splash screen, and customize the videoPlayerView.
See the getting-started guide for more information.
Documentation
The online documentation has more information, articles, code examples, etc.
Demo Application
The Demo folder has a demo app that lets you explore the library.
Support My Work
You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.
Contact
Feel free to reach out if you have questions, or want to contribute in any way:
- Website: danielsaidi.com
- E-mail: daniel.saidi@gmail.com
- Bluesky: @danielsaidi@bsky.social
- Mastodon: @danielsaidi@mastodon.social
License
VideoKit is available under the MIT license. See the LICENSE file for more info.
