New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-volume-manager

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-volume-manager

React Native module which adds the ability to change the system volume on iOS and Android, listen to volume changes and supress the native volume UI to build your own volume slider or UX.

  • 0.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
decreased by-13.01%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-volume-manager

Adds the ability to change the system volume on iOS and Android, listen to volume changes and supress the native volume UI to build your own volume slider or UX.

Installation

npm install react-native-volume-manager

or

yarn add react-native-volume-manager

Quick usage overview

import VolumeManager from 'react-native-volume-manager';

// ...

// set volume
VolumeManager.setVolume(0.5); // float value between 0 and 1

// set volume with extra options
VolumeManager.setVolume(0.5, {
  type: 'system', // defaults to "music" (Android only)
  showUI: true, // defaults to false, can surpress the native UI Volume Toast (iOS & Android)
  playSound: false, // defaults to false (when pushing hardware buttons) (Android only)
});

// get volume async, type defaults to "music" (Android only)
// iOS has only one type of Volume (system)
const { volume } = await VolumeManager.getVolume(type: 'music');

// or the oldschool way
VolumeManager.getVolume.then((result) => {
  console.log(result.volume); // returns the current volume as a float (0-1)
});


// listen to volume changes
useEffect(() => {
  const volumeListener = VolumeManager.addListener((result) => {
    console.log(result.volume); // returns the current volume as a float (0-1)
  });

  // clean up function
  return function () {
      // remove listener
      volumeListener.remove();
  }
})

API

MethodDescription
Volume
getVolume(type:string) => PromiseGet the system volume.

type must be one of music, call, system, ring, alarm, notification, default is music. (Android only, iOS will always report the system volume)
setVolume(value:float, config:object)Set the system volume by specified value, from 0 to 1. 0 for mute, and 1 for the max volume.

config can be {type: 'music', playSound:true, showUI:true}

type : must be one of music, call, system, ring, alarm, notification, default is music. (Android only)
playSound: Whether to play a sound when changing the volume, default is false (Android only)
showUI: Show the native system volume UI, default is false (Android & iOS)
addListener(callback)Listen to volume changes (soft- and hardware. addListener will return the listener which is needed for cleanup. Result passed to callback contains volume as key.
listener.remove()Remove the listener when you don't need it anymore. Store the return of const listener = VolumeManager.addListener() in a variable and call it with .remove(). See the example above.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Thanks

Based on https://github.com/c19354837/react-native-system-setting, rewritten to TS and optimized for current React Native versions.

Keywords

FAQs

Package last updated on 02 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc