SDLoopingVideoView is a looping video-view based off of AVPlayerLayer; it works great when used as a video background (see below for list of apps using SDLoopingVideoView). SDLoopingVideoView automatically scales any video displayed to aspect-fill the view you define; scaling can be set manually as well. SDLoopingVideoView responds to any UIView animations and scales accordingly without interuption of the video playing.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Swift 5.0
SDLoopingVideoView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SDLoopingVideoView'
The easiest way to create a SDLoopingVideoView
is to drag and drop a UIView
in interface builder and set its class to SDLoopingVideoView
. Then, under the attributes inspector tab, set the videoName
property to the name of your video file and set the videoType
property to the extension of your video file.
You can also initialize an SDLoopingVideoView by declaring it in code:
let loopingVideoView = SDLoopingVideoView(frame: CGRect(x: 0, y: 0, width: 100, height: 100),
video: .video(fileName: "yourVideoName", fileExtension: .mpg))
Or if you want to also include a video to use in darkmode:
let loopingVideoViewWithDarkMode = SDLoopingVideoView(frame: CGRect(x: 0, y: 0, width: 100, height: 100),
video: .video(fileName: "yourVideoName", fileExtension: .mpg),
darkModeVideo: .video(fileName: "yourDarkModeVideoName", fileExtension: .mov))
You can also set scaling for each video separately:
let loopingVideoViewWithDarkModeAndCustomScaling = SDLoopingVideoView(frame: CGRect(x: 0, y: 0, width: 100, height: 100),
video: .video(fileName: "yourVideoName", fileExtension: .mpg, scaling: .resizeAspectFill),
darkModeVideo: .video(fileName: "yourDarkModeVideoName", fileExtension: .mov, scaling: .resizeAspect))
Simple!
You can setup multiple SDLoopingVideoViews to display simultaneously. (Video game footage taken from Velocity Breaker by Solsma Dev, available in the App Store.)
John Solsma (Solsma Dev Inc.), [email protected], http://SolsmaDev.com
If you're using SDLoopingVideoView in a public app, email me ([email protected]) and I will add it to the list!
SDLoopingVideoView is available under the MIT license. See the LICENSE file for more info.