diff --git a/RNSound/RNSound.m b/RNSound/RNSound.m index 8ff31019..c201febe 100644 --- a/RNSound/RNSound.m +++ b/RNSound/RNSound.m @@ -371,6 +371,12 @@ - (NSDictionary *)constantsToExport { [session setActive:true error:nil]; } +RCT_EXPORT_METHOD(getOutputLatency:(RCTResponseSenderBlock)callback) { + AVAudioSession *session = [AVAudioSession sharedInstance]; + double latency = session.outputLatency; + callback(@[@(latency)]); +} + + (BOOL)requiresMainQueueSetup { return YES; } diff --git a/index.d.ts b/index.d.ts index 81b77197..7422d7b7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -15,6 +15,8 @@ type BasePathType = string type CallbackType = (error: any) => void +type LatencyCallback = (latency: number) => void; + declare class Sound { static MAIN_BUNDLE: string static DOCUMENT: string @@ -50,6 +52,14 @@ declare class Sound { */ static setMode(mode: AVAudioSessionMode): void + /** + * Gets the current audio output latency + * This function is iOS only + * + * @param callback Function to receive the latency + */ + static getOutputLatency(callback: LatencyCallback): void + /** * @param filenameOrFile Either absolute or relative path to the sound file or the `require` call. * @param basePathOrCallback Optional base path of the file. Omit this or pass '' if filename is an absolute path; you may use one of the predefined directories: Sound.MAIN_BUNDLE, Sound.DOCUMENT, Sound.LIBRARY, Sound.CACHES. If you are using `require` to define filepath, then set the callback function as the second argument. @@ -196,7 +206,7 @@ declare class Sound { /** * Whether the player is playing or not. */ - isPlaying(): boolean + isPlaying(): boolean } export = Sound; diff --git a/package.json b/package.json index 024b1865..6aa29048 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-sound", - "version": "0.11.2", + "version": "0.11.3", "description": "React Native module for playing sound clips on iOS, Android, and Windows", "main": "sound.js", "typings": "index.d.ts", diff --git a/sound.js b/sound.js index c9bcbaf1..59c0388e 100644 --- a/sound.js +++ b/sound.js @@ -325,6 +325,12 @@ Sound.setSpeakerPhone = function(value) { } } +Sound.getOutputLatency = function(callback) { + if (!IsAndroid && !IsWindows) { + RNSound.getOutputLatency(callback) + } +} + Sound.MAIN_BUNDLE = RNSound.MainBundlePath; Sound.DOCUMENT = RNSound.NSDocumentDirectory; Sound.LIBRARY = RNSound.NSLibraryDirectory;