
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
react-native-audio-playback
Advanced tools
Play sounds with lowest latency in React Native using Google Oboe for Android and Audio Unit for iOS
⚡ Highest perf, lowest-latency react native library to play sounds on iOS/Android
For Android, it uses Google's C++ Oboe
For iOS, it uses Core Audio's Audio Unit
npm:
npm install react-native-audio-playback
yarn:
yarn add react-native-audio-playback
For iOS, run pod install in the ios directory.
AudioManager's shared static property and calling its setupAudioStream.
setupAudioStream takes in an optional options argument where you can pass in the sampleRate and channelCount of your audio files, or do not specify them and it will default to 44100 and 2 respectively.How do I know what sampleRate and channelCount I need to pass?
import { AudioManager } from 'react-native-audio-playback';
AudioManager.shared.setupAudioStream({ sampleRate: 44100, channelCount: 2 });
AudioManager.shared.loadSound(require('./assets/sound1.wav'));
AudioManager.shared.loadSound(require('./assets/sound2.wav'));
AudioManager.shared.openAudioStream();
From here you can manipulate the sounds individually:
player1.loopSound(true); // boolean whether to loop or not
player1.playSound();
player1.pauseSound();
player1.seekTo(1000); // timeInMs
or you can manipulate the same property for different sounds at once:
// multi play
AudioManager.shared.playSounds([
[player1, true],
[player2, true],
]);
AudioManager.shared.playSounds([
[player1, true],
[player2, false],
]); // you can play a sound while pausing the other
// multi loop
AudioManager.shared.loopSounds([
[player1, true],
[player2, true],
]);
Unload the sounds when you no longer need them:
player1.unloadSound();
player2.unloadSound();
The AudioManager is used to setup, open, close the audio stream, create audio sounds, manipulate multiple sounds simultaneously:
The AudioManager class is a singleton and can be accessed with its static shared property:
AudioManager.shared.<some-method>
setupAudioStream(options?: { sampleRate?: number; channelCount?: number; ios?: { audioSessionCategory?: IosAudioSessionCategory; }; android?: { usage?: AndroidAudioStreamUsage; }; }): void: sets up the Audio Stream to allow it later be opened.
Notes:
audioSessionCategory option in the ios object. Check apple docs for more info on the different audio session categories.usage option in the android object. Check here for the list of options.openAudioStream(): void: Opens the audio stream to allow audio to be played
Note: You should have called setupAudioStream before calling this method. You can't open a stream that hasn't been setuppauseAudioStream(): void: Pauses the audio stream (An example of when to use this is when user puts app to background)
Note: The stream has to be in open state. You cant pause a non open streamcloseAudioStream(): void: Closes the audio stream
Note: After this, you need to resetup the audio stream and then repon it to play sounds. The loaded sounds are still loaded and you dont have to reload them.loadSound(requiredAsset: number): Player: Loads a local audio sound and returns a Player instanceplaySounds(args: ReadonlyArray<[Player, boolean]>): void Plays/pauses multiple soundsloopSounds(args: ReadonlyArray<[Player, boolean]>): void Loops/unloops multiple soundsseekSoundsTo(args: ReadonlyArray<[Player, number]>): void Seeks multiple soundssetSoundsVolume(args: ReadonlyArray<[Player, number]>): void Sets the volume of multiple sounds, volume should be a number between 0 and 1.getStreamState(): StreamState Returns the current state of the stream.The Player class is used to manage a single sound created by an AudioManager.
playSound(): void: Plays the sound. If the sound is already playing it does nothing. If the sound is paused, it resumes it.pauseSound(): void: Pauses the soundseekTo(timeInMs: number): void: Seeks the sound to a given time in MillisecondssetVolume(volume: number): void: Sets the volume of the sound, volume should be a number between 0 and 1.unloadSound(): void: Unloads the audio memory, so the Player is useless after this point.If you don't know what is a Sample Rate or Channel Count and seem to be off-put by them! Don't be.
While these terms can be intimidating, it is really simple to understand enough to get this library working. One important thing to note is that all of your audio files should be in the same sample rate and channel count.
You most likely will work with audio files of sample rate of 44100 or 48000. To find out what sample rate your audio is in, you can use ffmpeg:
ffprobe -v error -select_streams a:0 -show_entries stream=sample_rate -of default=noprint_wrappers=1:nokey=1 <your-audio-file>.<ext>
If your audio files are of different sample rates, you can easily convert them to have them all be the same sample rate. My recommendation is convert the higher sample rates to the lower ones. So convert your 48000s to 44100s like this:
ffmpeg -i <your-audio-file>.ext -ar 44100 <new-name-for-converted-file>.<ext>
The most commont channel counts used for mobile is mono,1, or stereo, 2. In my opinion, most of the times you want to go with 2.
To know how many channels your audio file has:
ffprobe -v error -select_streams a:0 -show_entries stream=channels -of default=noprint_wrappers=1:nokey=1 <your-audio-file>.<ext>
If your audio files are of different channel counts, you can easily convert them to have them all be the same channel count. My recommendation is convert all the audio files with 1 channel to 2 channels like this:
ffmpeg -i <your-audio-file>.<ext> -ac 2 <new-name-for-converted-file>.<ext>
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
FAQs
Play sounds with lowest latency in React Native using Google Oboe for Android and Audio Unit for iOS
We found that react-native-audio-playback demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.