Latest 0.2.1
Homepage https://github.com/davidlondono/PlayerView
License MIT
Platforms ios 8.0, requires ARC
Authors ,

PlayerView

[![CI Status](http://img.shields.io/travis/David Alejandro/PlayerView.svg?style=flat)](https://travis-ci.org/David Alejandro/PlayerView)
Version
License
Platform

An elegant wraper API for AVPlayer to get events over Delegate so you dount need to use KVO

Installation

PlayerView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "PlayerView"

CocoaPods

PlayerView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :iOS, '8.0'
use_frameworks!

pod 'PlayerView'

Carthage

Installation is also available using the dependency manager Carthage.

To integrate, add the following line to your Cartfile:

github "davidlondono/PlayerView" >= 0.1.0

Swift Package Manager

Installation can be done with the Swift Package Manager, add the following in your Package.swift :

import PackageDescription

let package = Package(
    name: "PlayerView",
    dependencies: [
        .Package(url: "https://github.com/davidlondono/PlayerView.git", majorVersion: 0),
    ]
)

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Storyboard

Just add a view and add as a class on Identity inspector > Custom Class > Class, make sure to add Module if is imported externaly (Pod, Package manager ….)

import PlayerView
@IBOutlet var playerVideo: PlayerView!

Code

Just need to add de view as a normal View:

import PlayerView

let playerVideo = PlayerVideo()

//also could add frame:
// let playerVideo = PlayerVideo(frame: frame)
view.addSubView(playerVideo)

Control

//set aspect mode of video
//default AVLayerVideoGravityResizeAspectFill
playerVideo.fillMode = .ResizeAspect

//Set or Get the seconds of the current time of reproduction
//this will set to reproduce on 3.5 seconds
playerVideo.currentTime = 3.5

//define the time interval to get callback delegate of the current time of reproduction, default sends 60 times on 1 second
//default CMTimeMake(1, 60)
playerVideo.interval = CMTimeMake(1, 1)

//set and get the speed of reproduction
//if speed is set to 0, the video will pause (same as playerVideo.pause())
//if speed is set to 1,0, the video will pause (same as playerVideo.play())
playerVideo.rate = 0.5

//play the video at rate 1.0
playerVideo.play()

// pause the video on current time
playerVideo.pause()

// stop the video on current time
playerVideo.stop()

//to set the url of Video
if let url = NSURL(string: "http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_30mb.mp4") {
    playerVideo.url = url
}

Delegate

you could get event data from the PlayerView, just implement the delegate
all the functions are optionals

import PlayerView
import AVFoundation
    playerVideo.delegate = self

extension MyClass:PlayerViewDelegate {

    func playerVideo(player: PlayerView, statusPlayer: PlayerViewStatus, error: NSError?) {
        //got the status of the player
        //useful to know if is ready to play
        //if status is unknown then got the error
    }

    func playerVideo(player: PlayerView, statusItemPlayer: PlayerViewItemStatus, error: NSError?) {
        //some status got here first, this is the status of AVPlayerItem
        //useful to know if is ready to play
        //if status is unknown then got the error
    }

    func playerVideo(player: PlayerView, loadedTimeRanges: [PlayerviewTimeRange]) {
        //got the buffer of the video
        //to know the progress loaded

        //this will get the seconds of the end of the buffer
        //loadedTimeRanges.first!.end.seconds

    }

    func playerVideo(player: PlayerView, duration: Double) {
        //the player knows the duration of the video to reproduce on seconds
    }

    func playerVideo(player: PlayerView, currentTime: Double) {
        //executed using the playerVideo.interval
        //only executed when the is reproducing, on pause (rate == 1) this doesn't execute
        //default executed like 60 frames per seconds, so 60 times on a second
    }

    func playerVideo(player: PlayerView, rate: Float) {
        //if the speed of reproduction changed by pausing, playing or changing speed
    }

    func playerVideo(playerFinished player: PlayerView) {
        //when the video finishes the reproduction to the end
    }
}

Extra Info

  • If you like another shorcut, have a better implementation of something or just say thanks, just send me an email [[email protected]](mailto:[email protected]?subject=PlayerView is Awesome)

  • Im using a video on http, so I needed to add this on the info.plist to accept all on http,
    this is not safe to use on production, so better to add only trusted domains or use https
<key>NSAppTransportSecurity</key>
<dict>
    <!--Include to allow all connections (DANGER)-->
    <key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

Author

David Alejandro, [[email protected]](mailto:[email protected]?subject=PlayerView is Awesome)

License

PlayerView is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SS-PlayerView",
    "version": "0.2.1",
    "summary": "A UIView for videos using AVPlayer with delegate",
    "description": "This Library allows to set a video on a custom UIView by setting the callbacks on a delegate for easy use. this View implements the AVPlayer from AVFoundation",
    "homepage": "https://github.com/davidlondono/PlayerView",
    "license": "MIT",
    "authors": {
        "David Alejandro": "[email protected]",
        "Eddie Li": "[email protected]"
    },
    "source": {
        "git": "https://github.com/sandsmedia/PlayerView.git",
        "tag": "0.2.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*"
}

Pin It on Pinterest

Share This