Latest 0.0.2
Homepage https://github.com/VeinGuo/VGPlayer
License MIT License
Platforms ios 8.0, requires ARC
Dependencies SnapKit
Frameworks UIKit, AVFoundation, Foundation
Authors

VGPlayer

Swift
Build
License MIT
Platform
Cocoapod

Banners

Swift developed based on AVPlayer iOS player,support horizontal gestures Fast forward, pause, vertical gestures Support brightness and volume adjustment, support full screen, adaptive screen rotation direction.

中文介绍

Demonstration

demo1

demo2

Requirements

  • Swift 3
  • iOS 8.0+
  • Xcode 8

Features

  • [x] Support play local and network
  • [x] Background playback mode.
  • [x] Gesture Adjusts the volume and brightness as well as fast forward and backward.
  • [x] Support full screen
  • [x] Slide fast forward and backward
  • [x] Lock screen can also be rotated full screen
  • [x] Support replay media
  • [x] Support custom player view
  • [x] Support subtitle (format: srt & ass)

    TODO

  • [ ] Media Cache
  • [ ] Virtual reality

Update

  • 2017-6-13 v0.0.1
  • 2017-6-17 Support subtitle (format: srt & ass)

Usage

Play Video

// init 
self.player = VGPlayer(URL: url)
// or
self.player.replaceVideo(url)

Custom player view

  • Subclass VGPlayerView
  • Alloc VGPlaye when set up
let playeView = VGCustomPlayerView()
self.player = VGPlayer(playerView: playeView)

// customPlayerView
class VGCustomPlayerView: VGPlayerView {
    var playRate: Float = 1.0
    var rateButton = UIButton(type: .custom)

    override func configurationUI() {
        super.configurationUI()
        self.topView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.09701412671)
        self.bottomView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.09701412671)
        self.topView.addSubview(rateButton)
        rateButton.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel.snp.right).offset(10)
            make.centerY.equalTo(closeButton)
        }
        rateButton.tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        rateButton.setTitle("x1.0", for: .normal)
        rateButton.titleLabel?.font   = UIFont.boldSystemFont(ofSize: 12.0)
        rateButton.addTarget(self, action: #selector(onRateButton), for: .touchUpInside)
        rateButton.isHidden = false
    }

// .....more

AutoLayout use SnapKit

            self.player.replaceVideo(url)
        view.addSubview(self.player.displayView)

        self.player.play()
        self.player.backgroundMode = .proceed
        self.player.delegate = self
        self.player.displayView.delegate = self
        self.player.displayView.titleLabel.text = "China NO.1"
        self.player.displayView.snp.makeConstraints { [weak self] (make) in
            guard let strongSelf = self else { return }
            make.top.equalTo(strongSelf.view.snp.top)
            make.left.equalTo(strongSelf.view.snp.left)
            make.right.equalTo(strongSelf.view.snp.right)
            make.height.equalTo(strongSelf.view.snp.width).multipliedBy(3.0/4.0) // you can 9.0/16.0
        }

Background playback

  • Project setting

backgroundModes

  • AppDelegate settings
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        do
        {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        }
        catch let error as NSError
        {
            print(error)
        }
        return true
    }
  • VGPlayer Background playback mode to proceed
self.player.backgroundMode = .proceed

Delegate methods optional

// player delegate
    // play state
    func vgPlayer(_ player: VGPlayer, stateDidChange state: VGPlayerState)
    // playe Duration
    func vgPlayer(_ player: VGPlayer, playerDurationDidChange currentDuration: TimeInterval, totalDuration: TimeInterval)
    // buffer state
    func vgPlayer(_ player: VGPlayer, bufferStateDidChange state: VGPlayerBufferstate)
    // buffered Duration
    func vgPlayer(_ player: VGPlayer, bufferedDidChange bufferedDuration: TimeInterval, totalDuration: TimeInterval)
    // play error
    func vgPlayer(_ player: VGPlayer, playerFailed error: VGPlayerError)

// player view delegate
    /// fullscreen
    func vgPlayerView(_ playerView: VGPlayerView, willFullscreen fullscreen: Bool)
    /// close play view
    func vgPlayerView(didTappedClose playerView: VGPlayerView)
    /// displaye control
    func vgPlayerView(didDisplayControl playerView: VGPlayerView)

Installation

  • Download VGPlayer. Move to your project.

  • Cocoapods
platform :ios, '8.0'
use_frameworks!
pod 'VGPlayer'

Reference

License

MIT

Latest podspec

{
    "name": "VGPlayer",
    "version": "0.0.2",
    "summary": "A simple iOS video player in Swift",
    "description": "A simple iOS video player in Swift by Vein.",
    "license": {
        "type": "MIT License",
        "file": "LICENSE"
    },
    "homepage": "https://github.com/VeinGuo/VGPlayer",
    "authors": {
        "VeinGuo": "https://github.com/VeinGuo"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/VeinGuo/VGPlayer.git",
        "tag": "0.0.2"
    },
    "source_files": "VGPlayer/Classes/*.*",
    "resources": "VGPlayer/*.xcassets",
    "requires_arc": true,
    "dependencies": {
        "SnapKit": [
            "~> 3.2.0"
        ]
    },
    "frameworks": [
        "UIKit",
        "AVFoundation",
        "Foundation"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This