测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2016年12月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Oscar J. Irun 维护。
Swift 3 编写的可用于裁剪视频的自定义视频范围滑块。
ABVideoRangeSlider 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中。
pod "ABVideoRangeSlider"
要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install
。
ViewController
中插入一个 UIView
ABVideoRangeSlider
导入到您的 ViewController
中Control + Drag
将 UIView
拖动到创建 IBOutlet
的 ViewController
中@IBOutlet var videoRangeSlider: ABVideoRangeSlider!
ABVideoRangeSliderDelegate
// Set the video URL
var path = Bundle.main.path(forResource: "myVideo", ofType:"mp4")
videoRangeSlider.setVideoURL(videoURL: URL(fileURLWithPath: path!))
// Set the delegate
videoRangeSlider.delegate = self
// Set a minimun space (in seconds) between the Start indicator and End indicator
videoRangeSlider.minSpace = 60.0
// Set a maximun space (in seconds) between the Start indicator and End indicator - Default is 0 (no max limit)
videoRangeSlider.maxSpace = 120.0
// Set initial position of Start Indicator
videoRangeSlider.setStartPosition(seconds: 50.0)
// Set initial position of End Indicator
videoRangeSlider.setEndPosition(seconds: 150.0)
您可以使用以下方法显示/隐藏此指示器
videoRangeSlider.hideProgressIndicator()
videoRangeSlider.showProgressIndicator()
如果您想要更新位置
videoRangeSlider.updateProgressIndicator(seconds: elapsedTimeOfVideo)
您可以通过提供自定义 UIView
到 videoRangeSlider.startTimeView.backgroundView
来自定义时间标签的背景。
示例
let customView = UIView(frame: CGRect(x: 0,
y: 0,
width: 60,
height: 40))
customView.backgroundColor = .black
customView.alpha = 0.5
customView.layer.borderColor = UIColor.black.cgColor
customView.layer.borderWidth = 1.0
customView.layer.cornerRadius = 8.0
videoRangeSlider.startTimeView.backgroundView = customView
属性
// Shows the formatted time
timeLabel: UILabel
// UILabel's margins - Default = 5.0
marginTop: CGFloat
marginBottom: CGFloat
marginLeft: CGFloat
marginRight: CGFloat
// Background View
backgroundView : UIView
func didChangeValue(videoRangeSlider: ABVideoRangeSlider, startTime: Float64, endTime: Float64) {
print(startTime) // Prints the position of the Start indicator in seconds
print(endTime) // Prints the position of the End indicator in seconds
}
func indicatorDidChangePosition(videoRangeSlider: ABVideoRangeSlider, position: Float64) {
print(position) // Prints the position of the Progress indicator in seconds
}
// Customize the Start indicator with a custom image
let customStartIndicator = UIImage(named: "CustomStartIndicator")
videoRangeSlider.setStartIndicatorImage(image: customStartIndicator!)
// Customize the End indicator with a custom image
let customEndIndicator = UIImage(named: "CustomEndIndicator")
videoRangeSlider.setEndIndicatorImage(image: customEndIndicator!)
// Customize bottom and top border with a custom image
let customBorder = UIImage(named: "CustomBorder")
videoRangeSlider.setBorderImage(image: customBorder!)
// Customize Progress indicator with a custom image
let customProgressIndicator = UIImage(named: "CustomProgressIndicator")
videoRangeSlider.setProgressIndicatorImage(image: customProgressIndicator!)
如果您需要更新视频的缩略图,可以手动调用此方法。默认情况下,每次视图更改其边界时都会调用它。
videoRangeSlider.updateThumbnails()
ABVideoRangeSlider开源协议为MIT。更多信息请查看LICENSE文件。