Code Monkey home page Code Monkey logo

jpsvolumebuttonhandler's Introduction

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.

jpsvolumebuttonhandler's People

Contributors

jpsim avatar samyes avatar apple-ihack-geek avatar joshbernfeld avatar gliyao avatar nylki avatar mrgrauel avatar kronik avatar jondot avatar fitsyu avatar jeroenvollenbrock avatar joestelmach avatar mirceapasoi avatar nolanw avatar rsanchezsaez avatar atomicbird avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.