- July 11, 2025
- Mins Read
##### It does the following: * *Creates an AVPlayer object for you and plays a video from your app bundle*
Handles video looping
Handles app going to background and coming back to foreground
Handles seguing away and back again to the view that plays the video
Mutes the video and does not allow it to interrupt other audio services. For example, it does not stop music playing from your music app or a VoIP call
Have an awesome video that you want to show as your background
Drag and drop BackgroundVideo.swift
file to your Project navigator
Drag and drop the video to your project and make sure to check Copy items if needed
as well as Add to targets
(This is because the object will look at your app’s main bunddle)
var backgroundPlayer : BackgroundVideo? // Declare an instance of BackgroundVideo called backgroundPlayer
7. In your viewDidLoad()
method, initialize your instance with the view controller you’re using and the name of the video file with it's extension
as parameters (make sure you seperate your name and extension by a period). In the following code I’m passing the same view controller where I declared my instance, namely self
. Then, just call the function setUpBackground()
on your instance.
override func viewDidLoad() {
super.viewDidLoad()
// Initializing your instance
backgroundPlayer = BackgroundVideo(onViewController: self, withVideoURL: “test.mp4”) // Passing self and video name with extension
backgroundPlayer?.setUpBackground()
}
Do steps 1-3 from the Swift steps above, but instead of dragging BackgroundVideo.swift
, drag and drop BackgroundVideoObjC.h
and BackgroundVideoObjC.m
.
Go to the view controller where you want to display the video and declare an instance.
@property (strong, nonatomic) BackgroundVideoObjC *backgroundVideo;
3. Same as 5 from Swift steps, except use this code:
– (void)viewDidLoad {
self.backgroundVideo = [[BackgroundVideoObjC alloc] initOnViewController:self withVideoURL:@”test.mp4″];
[self.backgroundVideo setUpBackground];
}
A SwiftUI View that emits confetti with user-defined shapes, images, and text.
A colour wheel made all in SwiftUI. There are 2 different colour wheels to choose from. The first main one ...
A color picker implementation with color wheel appearance written in plain SwiftUI. It is compatible with UIColor and NSColor.
This repository is no longer maintained. Here's why: with the release of iOS 16 SwiftUI now enables most of the ...