Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps!

License

Notifications You must be signed in to change notification settings

jpsim/JPSVolumeButtonHandler

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ddd2149 · Nov 4, 2022

History

62 Commits
Nov 4, 2022
Feb 19, 2014
Sep 13, 2017
Feb 19, 2014
Sep 19, 2017

Repository files navigation

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

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.

About

JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps!

Resources

License

Stars

Watchers

Forks

Packages

No packages published