Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output latency #829

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions RNSound/RNSound.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 11 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -196,7 +206,7 @@ declare class Sound {
/**
* Whether the player is playing or not.
*/
isPlaying(): boolean
isPlaying(): boolean
}

export = Sound;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 6 additions & 0 deletions sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down