Skip to content

Latest commit

 

History

History
164 lines (112 loc) · 5.3 KB

README.md

File metadata and controls

164 lines (112 loc) · 5.3 KB

Player

Build Status Platform Pod Version Carthage compatible Swift Version GitHub license

Overview

Player is a simple cross-platform video player library written in Swift.

⚠️ Warning: version 0.9 has breaking API changes. ⚠️

Looking for...

Features

  • plays local media or streams remote media over HTTP
  • customizable UI and user interaction
  • no size restrictions
  • orientation change support
  • simple API

Future Features

  • use AVPlayerViewController for iOS/tvOS platforms

Installation

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"

Quick Start

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:

.resizeAspectFit (default) Player

.resizeAspectFill Player

.resizeStretch (aka please don't. I mean look at the poor thing) Player

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)
    }
    
}

macOS

On the macOS platform, the player can display media controls.

player.controlsStyle = .floating

The controls' style can be set to the following:

.none

.inline (default) Player

.minimal Player

.floating Player

Documentation

You can find the docs here. Documentation is generated with jazzy and hosted on GitHub-Pages.

Community

  • 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.

Used In

  • Cards — Awesome iOS 11 appstore cards written in swift 4.

Resources

License

Player is available under the MIT license, see the LICENSE file for more information.