How do you create a video splash screen without a control bar a Swift app
Asked on 2024-07-30
1 search
To create a video splash screen without a control bar in a Swift app, you can use the AVPlayerViewController
and customize its appearance. Here are the steps you can follow:
-
Initialize the AVPlayer and AVPlayerViewController:
import AVKit import SwiftUI struct VideoSplashScreen: UIViewControllerRepresentable { let player: AVPlayer func makeUIViewController(context: Context) -> AVPlayerViewController { let playerViewController = AVPlayerViewController() playerViewController.player = player playerViewController.showsPlaybackControls = false // Hide control bar return playerViewController } func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) { // No update needed } }
-
Embed the VideoSplashScreen in your SwiftUI view:
struct ContentView: View { var body: some View { VideoSplashScreen(player: AVPlayer(url: URL(string: "your_video_url_here")!)) .edgesIgnoringSafeArea(.all) // Make the video fullscreen } }
-
Play the video automatically:
struct VideoSplashScreen: UIViewControllerRepresentable { let player: AVPlayer func makeUIViewController(context: Context) -> AVPlayerViewController { let playerViewController = AVPlayerViewController() playerViewController.player = player playerViewController.showsPlaybackControls = false // Hide control bar player.play() // Start playing the video automatically return playerViewController } func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) { // No update needed } }
This approach ensures that the video plays without showing the control bar, providing a clean splash screen experience.
For more detailed information on customizing video playback in SwiftUI, you can refer to the session Build compelling spatial photo and video experiences from WWDC 2024.

Migrate your TVML app to SwiftUI
SwiftUI helps you build great apps on all Apple platforms and is the preferred toolkit for bringing your content into the living room with tvOS 18. Learn how to use SwiftUI to create familiar layouts and controls from TVMLKit, and get tips and best practices.

SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.

Tailor macOS windows with SwiftUI
Make your windows feel tailor-made for macOS. Fine-tune your app’s windows for focused purposes, ease of use, and to express functionality. Use SwiftUI to style window toolbars and backgrounds. Arrange your windows with precision, and make smart decisions about restoration and minimization.