Skip to content

Commit

Permalink
currentTime
Browse files Browse the repository at this point in the history
  • Loading branch information
jamfromouterspace committed Nov 19, 2023
1 parent 6ef05a0 commit 15974c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ios/AudioProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AudioProcessor {
if metadata == nil {
return
}
try! AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
if startFrom != nil {
player.stop()
let frameCount = AVAudioFrameCount(metadata!.totalSamples - UInt32(startFrom!))
Expand Down Expand Up @@ -129,7 +130,7 @@ class AudioProcessor {
} else {
bandMagnitudes = calculateLogarithmicBands(fftData: rawMagnitudes, numberOfBands: numBands)
}
let currentTime = currentTime(sampleTime: time)
let currentTime = currentTime()
// send to JS thread
onData(fftMagnitudes, bandMagnitudes, bandFrequencies, loudness, currentTime)
}
Expand Down Expand Up @@ -286,7 +287,7 @@ class AudioProcessor {
return Float((startFrequency + endFrequency) / 2)
}

func currentTime(sampleTime: AVAudioTime) -> Double {
func currentTime() -> Double {
if metadata == nil {
return 0
}
Expand Down
4 changes: 4 additions & 0 deletions ios/ExpoAudioFFTModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class ExpoAudioFFTModule: Module {
})
}

Function("currentTime") {
return audioProcessor?.currentTime()
}

Function("load") { localUri in
audioProcessor?.load(localUri: localUri)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-audio-fft",
"version": "0.1.0",
"version": "0.1.3",
"description": "Get waveform and frequency data from an audio file",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export function seek(toSeconds: number): string {
return ExpoAudioFFTModule.seek(toSeconds);
}

export function currentTime(): number {
return ExpoAudioFFTModule.currentTime();
}

export type AudioMetadata = {
duration: number,
numChannels: number,
Expand Down

0 comments on commit 15974c6

Please sign in to comment.