▶️ Play and stream media in Swift
Player
is a simple iOS video player library written in Swift.
Need a different version of Swift?
5.0
- Target your Podfile to the latest release or master4.2
- Target your Podfile to the swift4.2
branch4.0
- Target your Podfile to the swift4.0
branchPlayer
is available for installation using the Cocoa dependency manager CocoaPods. Alternatively, you can simply copy the Player.swift
file into your Xcode project.
# CocoaPods
pod "Player", "~> 0.13.2"
# Carthage
github "piemonte/Player" ~> 0.13.2
The sample project provides an example of how to integrate Player
, otherwise you can follow these steps.
Allocate and add the Player
controller to your view hierarchy.
self.player = Player()
self.player.playerDelegate = self
self.player.playbackDelegate = self
self.player.view.frame = self.view.bounds
self.addChild(self.player)
self.view.addSubview(self.player.view)
self.player.didMove(toParent: 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
self.player.url = videoUrl
play/pause
self.player.playFromBeginning()
Adjust the fill mode for the video, if needed.
self.player.fillMode = .resizeAspectFit
Display video playback progress, if needed.
extension ViewController: PlayerPlaybackDelegate {
public func playerPlaybackWillStartFromBeginning(_ player: Player) {
}
public func playerPlaybackDidEnd(_ player: Player) {
}
public func playerCurrentTimeDidChange(_ player: Player) {
let fraction = Double(player.currentTime) / Double(player.maximumDuration)
self._playbackViewController?.setProgress(progress: CGFloat(fraction), animated: true)
}
public func playerPlaybackWillLoop(_ player: Player) {
self. _playbackViewController?.reset()
}
}
You can find the docs here. Documentation is generated with jazzy and hosted on GitHub-Pages.
Player is available under the MIT license, see the LICENSE file for more information.