https://github.com/alloc/react-native-sound
Sound effect player for react-native-macos
https://github.com/alloc/react-native-sound
react-native react-native-macos
Last synced: 4 months ago
JSON representation
Sound effect player for react-native-macos
- Host: GitHub
- URL: https://github.com/alloc/react-native-sound
- Owner: alloc
- Created: 2019-03-20T23:59:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-06T16:39:22.000Z (over 6 years ago)
- Last Synced: 2025-01-11T21:33:12.629Z (about 1 year ago)
- Topics: react-native, react-native-macos
- Language: Swift
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @alloc/react-native-sound
Sound effect player for [react-native-macos](https://github.com/ptmt/react-native-macos)
Compatible with __macOS 10.13+__ only.
```ts
import {Sound} from '@alloc/react-native-sound'
// When a Sound is constructed, its source is pre-loaded.
const foo = new Sound({
source: require('./foo.wav'),
// Throttle the sound to once per second
timeout: 1000,
// The volume limit (between 0 and 1)
volume: 0.5,
// Mute the sound without modifying `volume`
muted: true,
// Called once the sound is ready to play
onLoad: () => {},
// Called when the sound fails to load
onError: (error) => {
// The default behavior
throw error
},
})
// Play once
foo.play()
// Some options can be mutated after creation
foo.volume = 0
foo.muted = false
// Release memory
foo.dispose()
```
## Notes
⚠️ Audio must be `.wav` format (48kHz 32bit)
Thanks to [Starling](https://github.com/matthewreagan/Starling) for providing much of the native implementation.
Type definitions included!! (TypeScript only)