Giter Site home page Giter Site logo

andrewboryk / abvolumecontrol Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 4.0 737 KB

A custom volume control that replaces MPVolumeView, with multiple styles available, and a delegate to implement one's own custom volume view.

License: MIT License

Ruby 8.77% Objective-C 60.37% Shell 30.86%
mpmediaplayer volume control mpmusicplayercontroller custom customizable custom-volume delegate

abvolumecontrol's Introduction

ABVolumeControl custom logo

Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Screenshots

Description

A custom volume control that replaces MPVolumeView. There are several styles for ABVolumeControl, along with a delegate for creating one's own custom volume slider.

Requirements

  • Requires iOS 8.0 or later
  • Requires Automatic Reference Counting (ARC)
  • Requires MediaPlayer framework

Installation

ABVolumeControl is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ABVolumeControl"

Initialization

ABVolumeControl is initialized by calling 'setVolumeControlStyle:' on the sharedManager for ABVolumeControl. There are several different settings available for the style of an ABVolumeControl. Without setting the style of the control, there will be no visible ABVolumeControl.

// The first style for an ABVolumeControl is minimal, which is a 2px-tall bar that is visible at the top of the screen above the UIStatusBar.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleMinimal];

// Set the ABVolumeControl style to Status Bar style. This style is similar to the 'minimal' style, with added space between the control and the top of the screen, allowing the control to cover the UIStatusBar. This makes the control more visible.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleStatusBar];

// One can remove the custom ABVolumeControl by setting the volumeControlStyle to ABVolumeControlStyleNone. This would bring back the original MPVolumeView.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleNone];

// Setting the volumeControlStyle to custom ensures that the MPVolumeView is not shown, and no ABVolumeControl appears. There is a delegate available to listen to changes in the user's volume, and communicate changes in a custom volume slider to the rest of the application.
[[ABVolumeControl sharedManager] setVolumeControlStyle:ABVolumeControlStyleCustom];

Customization

There are settings available for modifying the appearance of an ABVolumeControl, allowing the change of color for the ABVolumeControl easily.

// Changing the theme of the ABVolumeControl allows for easy access to modifying the appearance of the ABVolumeControl depending on it's surroundings (Dark backgrounds vs Light backgrounds)
[[ABVolumeControl sharedManager] setControlTheme: ABVolumeControlDarkTheme];

In addition to setting the controlTheme, the accent colors for the dark and light themes can be set individually.

// Changes the accent color associated with the ABVolumeControlDarkTheme theme
[[ABVolumeControl sharedManager] setDefaultDarkColor:[UIColor blueColor]];

// Changes the accent color associated with the ABVolumeControlLightTheme theme
[[ABVolumeControl sharedManager] setDefaultLightColor:[UIColor yellowColor]];

The volume of the user's device can be adjusted progamically by calling the method 'setVolumeLevel:' on the sharedManager.

[[ABVolumeControl sharedManager] setVolumeLevel:0.5f];

The volume bar can be manually hidden and shown using the 'hideVolumeControl' and 'showVolumeControl' methods. 'hideVolumeControl' hides the ABVolumeControl immediately, and ensures that it won't be shown for 1 second after being called. 'showVolumeControl' displays the ABVolumeControl with animation. There is also a variable 'volumeControlHidden' that sets the ABVolumeControl not to show indefinitely, until specified otherwise.

// Ensures that the ABVolumeControl will not be shown for 1 second time, and hides it immediately
[[ABVolumeControl sharedManager] hideVolumeControl];

// Displays the ABVolumeControl with animation
[[ABVolumeControl sharedManager] showVolumeControl];

// Makes sure that the ABVolumeControl will not be displayed until specified otherwise.
[[ABVolumeControl sharedManager] setVolumeControlHidden: YES];

Delegate

When using ABVolumeControlStyleCustom or just looking to monitor the current volume level of the user's device easily, one can use the following delegate:

// Set delegate for the volume control to be used for custom volume sliders
[[ABVolumeControl sharedManager] setVolumeDelegate:self];
    
// Volume did change in the ABVolumeControl to the value 'volumePercentage' (0.0 - 1.0)
- (void)control:(ABVolumeControl *)control didChangeVolume:(CGFloat)volumePercentage;

Also, when looking to know when the volumeControl will/did present and dismiss, delegate methods have been provided. These methods are called for ABVolumeControlStyleMinimal and ABVolumeControlStyleStatusBar.

// ABVolumeControl will be displayed
- (void)controlWillPresent:(ABVolumeControl *)control;

// ABVolumeControl was displayed
- (void)controlDidPresent:(ABVolumeControl *)control;

// ABVolumeControl will be dismissed
- (void)controlWillDismiss:(ABVolumeControl *)control;

// ABVolumeControl was dismissed
- (void)controlDidDismiss:(ABVolumeControl *)control;

Author

andrewboryk, [email protected]

Reach out to me on Twitter @TrepIsLife alt text

License

ABVolumeControl is available under the MIT license. See the LICENSE file for more info.

abvolumecontrol's People

Contributors

andrewboryk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.