JPSVolumeButtonHandler
JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps!
Install / Use
/learn @jpsim/JPSVolumeButtonHandlerREADME
JPSVolumeButtonHandler
JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps! Used in JPSImagePickerController.
Features:
- Run blocks whenever a hardware volume button is pressed
- Volume button presses don't affect system audio
- Hide the HUD typically displayed on volume button presses
- Works even when the system audio level is at its maximum or minimum, even when muted
Installation
Swift Package Manager (SPM)
Add: https://github.com/jpsim/JPSVolumeButtonHandler.git (master branch) to your "Package Dependencies" in XCode.
Or add: .package(url: "https://github.com/jpsim/JPSVolumeButtonHandler.git", branch: "master") to your swift package file.
From CocoaPods
Add pod 'JPSVolumeButtonHandler' to your Podfile.
Manually
Drag the JPSVolumeButtonHandler folder into your project and link the MediaPlayer and AVFoundation frameworks to your project.
Usage
Set your blocks to be run when the volume buttons are pressed:
self.volumeButtonHandler = [JPSVolumeButtonHandler volumeButtonHandlerWithUpBlock:^{
// Volume Up Button Pressed
} downBlock:^{
// Volume Down Button Pressed
}];
To enable/disable the handler:
// Start
[self.volumeButtonHandler startHandler:YES];
// Stop
[self.volumeButtonHandler stopHandler];
To change audio session category (by default AVAudioSessionCategoryPlayAndRecord):
// Set category
self.volumeButtonHandler.sessionCategory = AVAudioSessionCategoryAmbient;
To change the audio session category options (by default AVAudioSessionCategoryOptionMixWithOthers):
self.volumeButtonHandler.sessionOptions = AVAudioSessionCategoryOptionAllowBluetooth|AVAudioSessionCategoryOptionMixWithOthers;
Note that not all options are compatible with all category options. See AVAudioSession documentation for details.
License
This project is under the MIT license.
Related Skills
node-connect
342.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
85.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
342.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
