@dashdoc/react-native-system-sounds
v1.1.0
Published
A module to play system sounds and beeps for React Native on iOS and Android (no sound files).
Downloads
5,271
Readme
@dashdoc/react-native-system-sounds
A module to play system sounds and beeps for React Native on iOS and Android (no sound files).
Heavily inspired by react-native-a-beep
Built with react-native-module-init
Installation
Mostly automatic install with autolinking (RN > 0.60)
- Install package from npm
yarn add @dashdoc/react-native-system-sounds
- Install iOS Pods
cd ios && pod install && cd ..
Mostly automatic install with react-native link (RN < 0.60)
- Install package from npm
yarn add @dashdoc/react-native-system-sounds
- Link package with react-native link
yarn react-native link @dashdoc/react-native-system-sounds
- Install iOS Pods
cd ios && pod install && cd ..
Usage
import RNSystemSounds from '@dashdoc/react-native-system-sounds';
// ...
<Button
title="Play positive beep"
onPress={() => RNSystemSounds.beep()}
/>
<Button
title="Play negative beep"
onPress={() => RNSystemSounds.beep(RNSystemSounds.Beeps.Negative)}
/>
<Button
title="Play custom system sound"
onPress={() =>
RNSystemSounds.play(
Platform.select({
android: RNSystemSounds.AndroidSoundIDs.TONE_CDMA_ABBR_ALERT,
ios: RNSystemSounds.iOSSoundIDs.AudioToneBusy,
})
)
}
/>
Example
- Clone the repository, enter the
example
directory and install dependencies.
git clone [email protected]:dashdoc/react-native-system-sounds.git
cd example/
yarn install
- Install iOS Pods,
cd ios && pod install && cd ..
- Start bundler.
yarn start
- On a new terminal, run the app on the
<platform>
of your choice (ios
orandroid
).
cd example/
yarn <platform>
Caveats
This does not work on iOS simulator.