BrikerMan/BMPlayer

Name: BMPlayer

Description: A video player for iOS, based on AVPlayer, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, support subtitles.

Created: 2016-04-28 10:13:42.0

Updated: 2018-01-19 07:08:44.0

Pushed: 2018-01-16 02:54:53.0

Homepage: https://eliyar.biz

Size: 20976

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

BMPlayer

Swift 2.2 Swift 3.0 Carthage compatible Version License Platform Weibo

A video player for iOS, based on AVPlayer, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, support subtitles.

????

Features
Requirements
Installation
CocoaPods
Swift 4
frameworks!

'BMPlayer', '~> 1.0.0'
Swift 3
frameworks!

'BMPlayer', '~> 0.9.1'
Swift 2.2
frameworks!

'BMPlayer', '~> 0.3.3'

To test the experimental caching support with VIMediaCache, use

'BMPlayer/CacheSupport', :git => 'https://github.com/BrikerMan/BMPlayer.git'
Carthage

Add BMPlayer in your Cartfile.

ub "BrikerMan/BMPlayer"

Run carthage to build the framework and drag the built BMPlayer.framework into your Xcode project.

Demo

run pod install at Example folder before run the demo.

Usage ?Support IB and code?
Set status bar color

Please add the View controller-based status bar appearance field in info.plist and change it to NO

IB usage

Direct drag IB to UIView, the aspect ratio for the 16:9 constraint (priority to 750, lower than the 1000 line), the code section only needs to achieve. See more detail on the demo.

rt BMPlayer

er.playWithURL(URL(string: url)!)

er.backBlock = { [unowned self] (isFullScreen) in
if isFullScreen == true { return }
let _ = self.navigationController?.popViewController(animated: true)

Code implementation by SnapKit
rt BMPlayer

er = BMPlayer()
.addSubview(player)
er.snp.makeConstraints { (make) in
make.top.equalTo(self.view).offset(20)
make.left.right.equalTo(self.view)
// Note here, the aspect ratio 16:9 priority is lower than 1000 on the line, because the 4S iPhone aspect ratio is not 16:9
make.height.equalTo(player.snp.width).multipliedBy(9.0/16.0).priority(750)

ack button event
er.backBlock = { [unowned self] (isFullScreen) in
if isFullScreen == true { return }
let _ = self.navigationController?.popViewController(animated: true)

Set video url
asset = BMPlayerResource(url: URL(string: "http://baobab.wdjcdn.com/14525705791193.mp4")!,
                         name: "???????????")
er.setVideo(resource: asset)
multi-definition video with cover
res0 = BMPlayerResourceDefinition(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
                                  definition: "??")
res1 = BMPlayerResourceDefinition(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
                                  definition: "??")

asset = BMPlayerResource(name: "???????????",
                         definitions: [res0, res1],
                         cover: URL(string: "http://img.wdjimg.com/image/video/447f973848167ee5e44b67c8d4df9839_0_0.jpeg"))

er.setVideo(resource: asset)
Add HTTP header for request
header = ["User-Agent":"BMPlayer"]
options = ["AVURLAssetHTTPHeaderFieldsKey":header]

definition = BMPlayerResourceDefinition(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
                                        definition: "??",
                                        options: options)

asset = BMPlayerResource(name: "Video Name",
                         definitions: [definition])
Listening to player state changes

See more detail from the Example project

Block
sten to when the player is playing or stopped
er?.playStateDidChange = { (isPlaying: Bool) in
print("playStateDidChange \(isPlaying)")


sten to when the play time changes
er?.playTimeDidChange = { (currentTime: TimeInterval, totalTime: TimeInterval) in
print("playTimeDidChange currentTime: \(currentTime) totalTime: \(totalTime)")

Delegate
ocol BMPlayerDelegate {
func bmPlayer(player: BMPlayer ,playerStateDidChange state: BMPlayerState) { }
func bmPlayer(player: BMPlayer ,loadedTimeDidChange loadedDuration: TimeInterval, totalDuration: TimeInterval)  { }
func bmPlayer(player: BMPlayer ,playTimeDidChange currentTime : TimeInterval, totalTime: TimeInterval)  { }
func bmPlayer(player: BMPlayer ,playerIsPlaying playing: Bool)  { }

Customize player

Needs to change before the player alloc.

hould print log, default false
ayerConf.allowLog = false
hould auto play, default true
ayerConf.shouldAutoPlay = true
ain tint color, default whiteColor
ayerConf.tintColor = UIColor.whiteColor()
ptions to show header view (which include the back button, title and definition change button) , default .Always?options: .Always, .HorizantalOnly and .None
ayerConf.topBarShowInCase = .Always
oader type, see detail?https://github.com/ninjaprox/NVActivityIndicatorView
ayerConf.loaderType  = NVActivityIndicatorType.BallRotateChase
nable setting the brightness by touch gesture in the player
ayerConf.enableBrightnessGestures = true
nable setting the volume by touch gesture in the player
ayerConf.enableVolumeGestures = true
nable setting the playtime by touch gesture in the player
ayerConf.enablePlaytimeGestures = true
Advanced Customize
Demonstration

gif

Reference:

This project heavily reference the Objective-C version of this project ZFPlayer, thanks for the generous help of ZFPlayer's author.

Contact me?
Contributors

You are welcome to fork and submit pull requests.

License

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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.