A simple video player for iOS, based on AVPlayer, pure swift.
- Support for horizontal and vertical play mode
- Support play with online URL and local file
- Adjust brightness by slide vertical at left side of screen
- Adjust volume by slide vertical at right side of screen
- Slide horizontal to fast forward and rewind
- Support multi-definition video
- Mirror mode, slow play mode
- iOS 8 +
- Xcode 8
- Swift 3
Please make sure using the cocoapods 1.1.0.rc.2, update with sudo gem install cocoapods --pre
.
use_frameworks!
pod 'BMPlayer', :git => 'https://github.com/BrikerMan/BMPlayer.git'
pod 'NVActivityIndicatorView', :git => 'https://github.com/ninjaprox/NVActivityIndicatorView.git'
use_frameworks!
pod 'BMPlayer', '~> 0.3.3'
run pod install
at Example
folder before run the demo.
Please add the View controller-based status bar appearance
field in info.plist and change it to NO
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.
import BMPlayer
player.playWithURL(URL(string: url)!)
player.backBlock = { [unowned self] in
let _ = self.navigationController?.popViewController(animated: true)
}
Code implementation by SnapKit
import BMPlayer
player = BMPlayer()
view.addSubview(player)
player.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)
}
// Back button event
player.backBlock = { [unowned self] in
let _ = self.navigationController?.popViewController(animated: true)
}
player.playWithURL(URL(string: "http://baobab.wdjcdn.com/14571455324031.mp4")!, title: "风格互换:原来你我相爱")
let resource0 = BMPlayerItemDefinitionItem(url: URL(string: "http://baobab.wdjcdn.com/14570071502774.mp4")!, definitionName: "HD")
let resource1 = BMPlayerItemDefinitionItem(url: URL(string: "http://baobab.wdjcdn.com/1457007294968_5824_854x480.mp4")!, definitionName: "SD")
let item = BMPlayerItem(title: "周末号外丨川普版权力的游戏",
resource: [resource0, resource1],
cover: "http://img.wdjimg.com/image/video/acdba01e52efe8082d7c33556cf61549_0_0.jpeg")
Needs to change before the player alloc.
// should print log, default false
BMPlayerConf.allowLog = false
// should auto play, default true
BMPlayerConf.shouldAutoPlay = true
// main tint color, default whiteColor
BMPlayerConf.tintColor = UIColor.whiteColor()
// options to show header view (which include the back button, title and definition change button) , default .Always,options: .Always, .HorizantalOnly and .None
BMPlayerConf.topBarShowInCase = .Always
// show mirror mode, slow play mode button, default false
BMPlayerConf.slowAndMirror = true
// loader type, see detail:https://github.com/ninjaprox/NVActivityIndicatorView
BMPlayerConf.loaderType = NVActivityIndicatorType.BallRotateChase
This project heavily reference the Objective-C version of this project ZFPlayer, thanks for the generous help of ZFPlayer's author.
- Blog: https://eliyar.biz
- Email: eliyar917@gmail.com
BMPlayer is available under the MIT license. See the LICENSE file for more info.