Player is a simple cross-platform video player library written in Swift.
- An obj-c video player? Check out PBJVideoPlayer (obj-c).
- A Swift camera library? Check out Next Level.
- plays local media or streams remote media over HTTP
- customizable UI and user interaction
- no size restrictions
- orientation change support
- simple API
- use
AVPlayerViewController
for iOS/tvOS platforms
Player
is available for installation using the Cocoa dependency manager CocoaPods & Carthage. Alternatively, you can simply copy the Player.swift
file into your Xcode project.
Using CocoaPods
pod "Player"
Need Swift 3? Use release 0.7.0
pod "Player", "~> 0.7.0"
Using Carthage
github "piemonte/Player"
The sample projects provide an example of how to integrate Player
, otherwise you can follow these steps.
Create and add the Player
to your view controller.
let player = Player()
player.playerDelegate = self
player.playbackDelegate = self
player.view.frame = view.bounds
player.add(to: self)
Provide the file path to the resource you would like to play locally or stream. Ensure you're including the file extension.
let videoUrl: URL = // file or http url
player.url = videoUrl
play/pause/chill
player.playFromBeginning()
Adjust the fill mode for the video, if needed.
player.fillMode = .resizeAspectFit
The fill mode can be set to the following values:
.resizeStretch
(aka please don't. I mean look at the poor thing)
Display video playback progress, if desired. Note, all delegate methods are optional.
extension ViewController: PlayerPlaybackDelegate {
public func playerPlaybackWillStartFromBeginning(player: Player) {}
public func playerPlaybackDidEnd(player: Player) {}
public func playerCurrentTimeDidChange(player: Player) {
let currentProgress = Float(player.currentTime / player.maximumDuration)
progressView.setProgress(currentProgress, animated: true)
}
public func playerPlaybackWillLoop(player: Player) {
progressView.setProgress(0.0, animated: false)
}
}
On the macOS platform, the player can display media controls.
player.controlsStyle = .floating
The controls' style can be set to the following:
.none
You can find the docs here. Documentation is generated with jazzy and hosted on GitHub-Pages.
- Need help? Use Stack Overflow with the tag 'player-swift'.
- Questions? Use Stack Overflow with the tag 'player-swift'.
- Found a bug? Open an issue.
- Feature idea?
Open an issue.Do it yourself & PR when done 😅. - Want to contribute? Submit a pull request.
- Cards — Awesome iOS 11 appstore cards written in swift 4.
- Swift Evolution
- AV Foundation Programming Guide
- Next Level, rad media capture in Swift
- PBJVision, iOS camera engine, features touch-to-record video, slow motion video, and photo capture
- PBJVideoPlayer, a simple iOS video player library, written in obj-c
Player is available under the MIT license, see the LICENSE file for more information.