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 CocoaPods or 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()
// Optional
player.playerDelegate = self
// Optional
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.
player.url = URL(string: "https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/meet-iphone-x/iphone-x-meet-iphone-tpl-cc-us-20171129_1280x720h.mp4")
play/pause/chill 🏖️
player.playFromBeginning()
player.pause()
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 😅 (or you can open an issue). - Want to contribute? Submit a pull request.
- Cards — Awesome iOS 11 appstore cards written in Swift.
- 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
- Patrick Piemonte — Original author, iOS/tvOS platforms.
- Chris Zielinski — macOS platform.
Player is available under the MIT license, see the LICENSE file for more information.