Swiftpack.co - nsprt/NSPRTVideoPlayer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nsprt.
nsprt/NSPRTVideoPlayer 1.0.0
A beautiful out of the box video player with SPM
⭐️ 1
🕓 3 years ago
iOS
.package(url: "https://github.com/nsprt/NSPRTVideoPlayer.git", from: "1.0.0")

NSPRTVideoPlayer

Swift 5.0 SPM

A beautiful video player created for use with SPM.

Playing Paused

Requirements

  • iOS 12.0+

Installation

Xcode Projects

Using Xcode, select File -> Swift Packages -> Add Package Dependency and enter https://github.com/NSPRT/NSPRTVideoPlayer.

Install via the Swift Package Manager

Add the following to your Package.swift

    .Package(url: "https://github.com/nsprt/NSPRTVideoPlayer.git", majorVersion: 1)

Then simply import NSPRTVideoPlayer wherever you’d like to use it.

Getting Started

Create an instance of NSPRTVideoPlayerView with an initial CGRect, initialize a NSPRTPlayerItem with your video URL, and set the item in the NSPRTVideoPlayerView:

let playerView = NSPRTVideoPlayerView(frame: CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.width * (9/16)))
let item = NSPRTPlayerItem(url: url)
playerView?.set(item: item)

Create an instance of NSPRTVideoPlayerControls and pass that to our NSPRTVideoPlayerView with the use(controls: NSPRTVideoPlayerControls) function:

let controls = NSPRTVideoPlayerControls()
playerView.use(controls: controls)

Adding to View

The best way to add our player view is to have it nested in a subview, that way if a user enters full screen and exits fullscreen NSPRTVideoPlayerView automatically resizes back to its original placement:

let subView = UIView()
self.addSubview(subView)
subView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    subView.topAnchor.constraint(equalTo: topAnchor),
    subView.widthAnchor.constraint(equalTo: widthAnchor),
    subView.heightAnchor.constraint(equalToConstant: bounds.width * (9/16)), // 16:9 Aspect Ratio
    subView.centerXAnchor.constraint(equalTo: centerXAnchor)
    ])
    
subView.addSubview(playerView)
playerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    playerView.topAnchor.constraint(equalTo: subView.topAnchor),
    playerView.rightAnchor.constraint(equalTo: subView.rightAnchor),
    playerView.bottomAnchor.constraint(equalTo: subView.bottomAnchor),
    playerView.leftAnchor.constraint(equalTo: subView.leftAnchor)
    ])

Creator

NSPRT - [email protected]

License

NSPRTVideoPlayer is available under the MIT license.

GitHub

link
Stars: 1
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics