### Development Setup Commands Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/CONTRIBUTING.md Commands to clone the repository, install dependencies, build the library, generate Nitro module code, and run the example app for iOS, Android, and Web. ```bash # 1. Clone the repository git clone https://github.com/hyochan/react-native-nitro-sound.git cd react-native-nitro-sound # 2. Install root dependencies yarn # 3. Build the library (IMPORTANT: Must be done before running the example) yarn prepare # 4. Generate Nitro module code yarn nitrogen # 5. Install example dependencies and run the example app # For iOS: yarn example ios:pod # This will install pods using workspace yarn example ios # For Android: yarn example android # For Web: yarn example web # Starts development server at http://localhost:8080 # Or build for production: yarn example build:web ``` -------------------------------- ### Start Metro Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/example/README.md Commands to start the Metro dev server using npm or Yarn. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install CocoaPods dependencies Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/example/README.md Commands to install CocoaPods dependencies for iOS development. ```sh bundle install bundle exec pod install ``` -------------------------------- ### Running the Example App Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Instructions for installing dependencies, building the library, and running the example app on iOS and Android. ```sh yarn yarn prepare yarn start # iOS # First time on a new machine, you may need to install pods: (cd example/ios && pod install) yarn example ios # Android yarn example android ``` -------------------------------- ### Web Setup - Install react-native-web Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Install react-native-web for React Native Web support. ```sh yarn add react-native-web ``` -------------------------------- ### Build and run iOS app Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/example/README.md Commands to build and run the iOS app using npm or Yarn. ```sh # Using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### Build and run Android app Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/example/README.md Commands to build and run the Android app using npm or Yarn. ```sh # Using npm npm run android # OR using Yarn yarn android ``` -------------------------------- ### iOS Setup Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Install iOS native dependencies using CocoaPods. ```sh npx pod-install ``` -------------------------------- ### Coding Convention Example Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/CONTRIBUTING.md Example demonstrating the preferred coding convention for for loops and array forEach methods, with curly braces on the same line for declaration and the next line for closing. ```ts for (let i = 0; i < 10; i++) { ... } array.forEach((e) => { ... }); ``` -------------------------------- ### Migration Example Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Example showing how to update import statements when migrating from react-native-audio-recorder-player to react-native-nitro-sound. ```diff ```diff - import AudioRecorderPlayer from 'react-native-audio-recorder-player'; + import Sound from 'react-native-nitro-sound'; ``` ``` -------------------------------- ### Installation with Yarn Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Install react-native-nitro-sound and react-native-nitro-modules using Yarn. ```sh yarn add react-native-nitro-sound react-native-nitro-modules ``` -------------------------------- ### Installation with npm Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Install react-native-nitro-sound and react-native-nitro-modules using npm. ```sh npm install react-native-nitro-sound react-native-nitro-modules ``` -------------------------------- ### Web Setup - Webpack Configuration Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Configure webpack to alias 'react-native' to 'react-native-web' for web builds. ```js // webpack.config.js module.exports = { resolve: { alias: { 'react-native': 'react-native-web', }, }, }; ``` -------------------------------- ### Basic Usage Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Demonstrates fundamental recording and playback functionalities, including starting, stopping, pausing, resuming, seeking, and controlling volume and playback speed. ```typescript import Sound, { AudioEncoderAndroidType, AudioSourceAndroidType, AVEncoderAudioQualityIOSType, AVEncodingOption, RecordBackType, PlayBackType, } from 'react-native-nitro-sound'; // Sound is a singleton instance, use directly // Recording const onStartRecord = async () => { // Set up recording progress listener Sound.addRecordBackListener((e: RecordBackType) => { console.log('Recording progress:', e.currentPosition, e.currentMetering); setRecordSecs(e.currentPosition); setRecordTime(Sound.mmssss(Math.floor(e.currentPosition))); }); const result = await Sound.startRecorder(); console.log('Recording started:', result); }; const onStopRecord = async () => { const result = await Sound.stopRecorder(); Sound.removeRecordBackListener(); console.log('Recording stopped:', result); }; // Pause/Resume Recording const onPauseRecord = async () => { await Sound.pauseRecorder(); console.log('Recording paused'); }; const onResumeRecord = async () => { await Sound.resumeRecorder(); console.log('Recording resumed'); }; // Playback const onStartPlay = async () => { // Set up playback progress listener Sound.addPlayBackListener((e: PlayBackType) => { console.log('Playback progress:', e.currentPosition, e.duration); setCurrentPosition(e.currentPosition); setTotalDuration(e.duration); setPlayTime(Sound.mmssss(Math.floor(e.currentPosition))); setDuration(Sound.mmssss(Math.floor(e.duration))); }); // Set up playback end listener Sound.addPlaybackEndListener((e: PlaybackEndType) => { console.log('Playback completed:', e); // Handle playback completion setIsPlaying(false); setCurrentPosition(0); }); const result = await Sound.startPlayer(); console.log('Playback started:', result); }; const onPausePlay = async () => { await Sound.pausePlayer(); }; const onStopPlay = async () => { Sound.stopPlayer(); Sound.removePlayBackListener(); Sound.removePlaybackEndListener(); }; // Seeking const seekTo = async (milliseconds: number) => { await Sound.seekToPlayer(milliseconds); }; // Volume control const setVolume = async (volume: number) => { await Sound.setVolume(volume); // 0.0 - 1.0 }; // Speed control const setSpeed = async (speed: number) => { await Sound.setPlaybackSpeed(speed); // 0.5 - 2.0 }; ``` -------------------------------- ### Cross-Platform Configuration Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Example of configuring audio settings for cross-platform compatibility in React Native Nitro Sound. ```typescript const audioSet: AudioSet = { // Common settings automatically applied to the appropriate platform AudioSamplingRate: 44100, AudioEncodingBitRate: 128000, AudioChannels: 1, }; ``` ```typescript const meteringEnabled = true; // Enable audio metering const uri = await Sound.startRecorder( undefined, // Use default path audioSet, meteringEnabled ); ``` -------------------------------- ### iOS Configuration Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Example of configuring audio settings specifically for iOS, including sample rate, format, quality, channels, and mode. ```typescript const audioSet: AudioSet = { // iOS-specific settings AVSampleRateKeyIOS: 44100, AVFormatIDKeyIOS: AVEncodingOption.aac, AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high, AVNumberOfChannelsKeyIOS: 2, AVModeIOS: 'measurement', // Available options: 'gameChatAudio', 'measurement', 'moviePlayback', 'spokenAudio', 'videoChat', 'videoRecording', 'voiceChat', 'voicePrompt' }; ``` -------------------------------- ### Android Configuration Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Example of configuring audio settings specifically for Android, including encoder, source, sampling rate, bit rate, and channels. ```typescript const audioSet: AudioSet = { // Android-specific settings AudioEncoderAndroid: AudioEncoderAndroidType.AAC, AudioSourceAndroid: AudioSourceAndroidType.MIC, // Common audio settings (apply on Android as well) // Tip: prefer these for consistent quality AudioSamplingRate: 44100, AudioEncodingBitRate: 128000, AudioChannels: 1, }; ``` -------------------------------- ### Build, Test, and Development Commands Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/AGENTS.md Common commands for building, testing, and developing the project. ```bash yarn prepare yarn nitrogen yarn typecheck yarn lint yarn test yarn start yarn ios yarn android yarn web yarn clean ``` -------------------------------- ### Basic Styling Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/example/dist/index.html Basic CSS styling for the web demo. ```css html, body, #root { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; } ``` -------------------------------- ### iOS Clean Build Instructions Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Steps for performing a clean build on iOS to resolve build issues or runtime errors. ```sh cd ios rm -rf ~/Library/Caches/CocoaPods rm -rf Pods rm -rf ~/Library/Developer/Xcode/DerivedData/* pod cache clean --all pod install cd .. ``` ```text Product → Clean Build Folder (⇧⌘K) Product → Build (⌘B) ``` -------------------------------- ### Build the Plugin Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/plugin/README.md Commands to build the plugin locally. ```bash cd plugin npm install npm run build ``` -------------------------------- ### Basic CSS for Web Demo Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/example/public/index.html Basic CSS to ensure the demo takes up the full screen and has a default font. ```css html, body, #root { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; } ``` -------------------------------- ### Android Clean Build Instructions Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Steps for performing a clean build on Android to resolve build issues or runtime errors. ```sh cd android ./gradlew clean rm -rf ~/.gradle/caches/ cd .. ``` ```sh yarn android # or npx react-native run-android ``` -------------------------------- ### Modern API: Multiple Instances Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Illustrates how to create and manage multiple independent sound instances for concurrent playback or recording. ```tsx import { createSound } from 'react-native-nitro-sound'; // Create independent instances (recorder/player per instance) const soundA = createSound(); const soundB = createSound(); await soundA.startPlayer('https://example.com/a.mp3'); await soundB.startPlayer('https://example.com/b.mp3'); // Control them independently await soundA.pausePlayer(); await soundB.setVolume(0.5); // Clean up when done soundA.dispose(); soundB.dispose(); ``` -------------------------------- ### Android Runtime Permissions (Full Permissions Approach) Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Approach for older Android versions to request multiple permissions including storage and audio recording at runtime. ```typescript if (Platform.OS === 'android') { try { const grants = await PermissionsAndroid.requestMultiple([ PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, PermissionsAndroid.PERMISSIONS.RECORD_AUDIO, ]); if ( grants['android.permission.WRITE_EXTERNAL_STORAGE'] === PermissionsAndroid.RESULTS.GRANTED && grants['android.permission.READ_EXTERNAL_STORAGE'] === PermissionsAndroid.RESULTS.GRANTED && grants['android.permission.RECORD_AUDIO'] === PermissionsAndroid.RESULTS.GRANTED ) { console.log('All permissions granted'); } else { console.log('All required permissions not granted'); return; } } catch (err) { console.warn(err); return; } } ``` -------------------------------- ### iOS Minimum Deployment Target Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Set the minimum deployment target to iOS 13.0 or higher in your Podfile. ```ruby platform :ios, '13.0' ``` -------------------------------- ### CMakeLists.txt Configuration Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/android/CMakeLists.txt The CMakeLists.txt file defines the build configuration for the native Android library. ```cmake project(NitroSound) cmake_minimum_required(VERSION 3.9.0) set(PACKAGE_NAME NitroSound) set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_CXX_STANDARD 20) # Define C++ library and add all sources add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp) # Add Nitrogen specs :) include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/NitroSound+autolinking.cmake) # Workaround for NitroModules prefab not including the library # Find the actual library file set(NITRO_LIB_PATH "${CMAKE_SOURCE_DIR}/../example/node_modules/react-native-nitro-modules/android/build/intermediates/cmake/debug/obj/${ANDROID_ABI}/libNitroModules.so") if(EXISTS ${NITRO_LIB_PATH}) target_link_libraries(${PACKAGE_NAME} ${NITRO_LIB_PATH}) else() # Try alternate path set(NITRO_LIB_PATH "${CMAKE_SOURCE_DIR}/../example/node_modules/react-native-nitro-modules/android/build/intermediates/cxx/Debug/6w6i364c/obj/${ANDROID_ABI}/libNitroModules.so") if(EXISTS ${NITRO_LIB_PATH}) target_link_libraries(${PACKAGE_NAME} ${NITRO_LIB_PATH}) endif() endif() # Set up local includes include_directories("src/main/cpp" "../cpp") find_library(LOG_LIB log) # Link additional Android libraries target_link_libraries( ${PACKAGE_NAME} ${LOG_LIB} android # <-- Android core ) ``` -------------------------------- ### Android Runtime Permission (Minimal Approach) Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Recommended approach for Android 13+ to request microphone recording permission at runtime. ```typescript if (Platform.OS === 'android') { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.RECORD_AUDIO, { title: 'Audio Recording Permission', message: 'This app needs access to your microphone to record audio.', buttonNeutral: 'Ask Me Later', buttonNegative: 'Cancel', buttonPositive: 'OK', } ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('Recording permission granted'); } else { console.log('Recording permission denied'); return; } } catch (err) { console.warn(err); return; } } ``` -------------------------------- ### Steps to resolve Swift 6 compile error after upgrading Xcode Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/docs/FAQ.md This snippet outlines the steps to take after upgrading Xcode to resolve Swift 6 compile errors, including cleaning and reinstalling dependencies. ```bash yarn install pod install --clean-install ``` -------------------------------- ### Android Permissions Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Add necessary permissions to AndroidManifest.xml for internet, audio recording, and storage access. ```xml ``` -------------------------------- ### Align React Native Dependencies Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Align React Native dependencies to a specific version using @rnx-kit/align-deps. ```sh npx @rnx-kit/align-deps --requirements react-native@0.81 --write ``` -------------------------------- ### iOS Recording Error: "Unknown std::runtime_error" Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Troubleshooting steps for the iOS recording error, including Info.plist configuration, cleaning the build, and testing on a real device. ```xml NSMicrophoneUsageDescription Your app needs microphone access to record audio ``` ```sh cd ios rm -rf build Pods pod install cd .. yarn ios ``` -------------------------------- ### iOS Microphone Permission Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Add NSMicrophoneUsageDescription to your Info.plist for microphone access on iOS. ```xml NSMicrophoneUsageDescription Give $(PRODUCT_NAME) permission to use your microphone. Your record wont be shared without your permission. ``` -------------------------------- ### Basic Usage Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/plugin/README.md Add the plugin to your app.json or app.config.js for basic configuration. ```json { "expo": { "plugins": [ "react-native-nitro-sound" ] } } ``` -------------------------------- ### React Hook API Source: https://github.com/hyochan/react-native-nitro-sound/blob/main/README.md Shows how to use the `useSound` hook for managing audio playback within React components, including state management and controls. ```tsx import { useSound } from 'react-native-nitro-sound'; export function Player() { const { sound, state, startPlayer, pausePlayer, resumePlayer, stopPlayer, seekToPlayer, mmssss, } = useSound({ subscriptionDuration: 0.05, // 50ms updates }); return ( {mmssss(Math.floor(state.currentPosition))} /{' '} {mmssss(Math.floor(state.duration))}