VolumeButtons
VolumeButtons 是一种简单地处理 iPhone 或 iPad 上的硬件音量按钮点击的方法。
使用方法
self.volumeButtonHandler = VolumeButtonHandler(containerView: view)
volumeButtonHandler.buttonClosure = { button in
// ...
}
volumeButtonHandler.start()
工作原理
VolumeButtonHandler 类跟踪音频会话中的音量变化。当你增加或减少音量级别时,值将重置为初始值,因此按下按钮的判断不会改变媒体播放器的音量。你需要将用来放置用于控制音量级度的隐藏实例 MPVolumeView
的某个视图从你的 View Controller 的视图传递给 init
。
需求
iOS 11 及以上版本。
安装
可以通过 CocoaPods 获取 VolumeButtons。要安装它,只需将以下行添加到您的 Podfile
pod 'VolumeButtons'
参考文献
此项目基于 Objective-C 代码 JPSVolumeButtonHandler