### Start the Metro Server Source: https://github.com/zmxv/react-native-sound/blob/master/example/README.md Run the following command from the root of your React Native project to start Metro, the JavaScript bundler that ships with React Native. This server is required to bundle your application code. ```bash # using npm npm start ``` ```bash # OR using Yarn yarn start ``` -------------------------------- ### Start the Application for iOS Source: https://github.com/zmxv/react-native-sound/blob/master/example/README.md With the Metro Bundler running in a separate terminal, open a new terminal from the root of your project and run this command to build and launch your application on an connected iOS device or simulator. ```bash # using npm npm run ios ``` ```bash # OR using Yarn yarn ios ``` -------------------------------- ### Start the Application for Android Source: https://github.com/zmxv/react-native-sound/blob/master/example/README.md With the Metro Bundler running in a separate terminal, open a new terminal from the root of your project and run this command to build and launch your application on an connected Android device or emulator. ```bash # using npm npm run android ``` ```bash # OR using Yarn yarn android ``` -------------------------------- ### Basic Audio Playback and Control with react-native-sound (JavaScript) Source: https://github.com/zmxv/react-native-sound/blob/master/README.md This snippet demonstrates the fundamental usage of the react-native-sound library. It shows how to import the module, set the audio category, load a sound file from the app bundle, handle loading errors, play the sound with a completion callback, adjust volume and pan, set looping behavior, seek to a specific time, get current playback time, pause, stop, and finally release the sound resource. ```JavaScript // Import the react-native-sound module var Sound = require('react-native-sound'); // Enable playback in silence mode Sound.setCategory('Playback'); // Load the sound file 'whoosh.mp3' from the app bundle // See notes below about preloading sounds within initialization code below. var whoosh = new Sound('whoosh.mp3', Sound.MAIN_BUNDLE, (error) => { if (error) { console.log('failed to load the sound', error); return; } // loaded successfully console.log('duration in seconds: ' + whoosh.getDuration() + 'number of channels: ' + whoosh.getNumberOfChannels()); // Play the sound with an onEnd callback whoosh.play((success) => { if (success) { console.log('successfully finished playing'); } else { console.log('playback failed due to audio decoding errors'); } }); }); // Reduce the volume by half whoosh.setVolume(0.5); // Position the sound to the full right in a stereo field whoosh.setPan(1); // Loop indefinitely until stop() is called whoosh.setNumberOfLoops(-1); // Get properties of the player instance console.log('volume: ' + whoosh.getVolume()); console.log('pan: ' + whoosh.getPan()); console.log('loops: ' + whoosh.getNumberOfLoops()); // Seek to a specific point in seconds whoosh.setCurrentTime(2.5); // Get the current playback point in seconds whoosh.getCurrentTime((seconds) => console.log('at ' + seconds)); // Pause the sound whoosh.pause(); // Stop the sound and rewind to the beginning whoosh.stop(() => { // Note: If you want to play a sound after stopping and rewinding it, // it is important to call play() in a callback. whoosh.play(); }); // Release the audio player resource whoosh.release(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.