Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/common-app/src/examples/AudioFile/AudioFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AudioFile: FC = () => {
setIsPlaying(false);

setIsLoading(true);
await fetchAudioBuffer(result.assets[0].uri.replace('file://', ''));
await fetchAudioBuffer(result.assets[0].uri);
setIsLoading(false);
}
} catch (error) {
Expand Down
11 changes: 4 additions & 7 deletions apps/common-app/src/examples/AudioVisualizer/AudioVisualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@ const AudioVisualizer: React.FC = () => {
audioBufferRef.current = await FileSystem.downloadAsync(
URL,
FileSystem.documentDirectory + 'audio.mp3'
)
.then(({ uri }) => {
return uri.replace('file://', '');
})
.then((uri) => {
return audioContextRef.current!.decodeAudioDataSource(uri);
});
).then(({ uri }) => {
return audioContextRef.current!.decodeAudioDataSource(uri);
});

setIsLoading(false);
};

Expand Down
10 changes: 3 additions & 7 deletions apps/common-app/src/examples/Piano/Piano.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ const Piano: FC = () => {
bufferListRef.current[key as KeyName] = await FileSystem.downloadAsync(
url,
FileSystem.documentDirectory + key.replace('#', 's') + '.mp3'
)
.then(({ uri }) => {
return uri.replace('file://', '');
})
.then((uri) => {
return audioContextRef.current!.decodeAudioDataSource(uri);
});
).then(({ uri }) => {
return audioContextRef.current!.decodeAudioDataSource(uri);
});
});

const newNotes: Partial<Record<KeyName, PianoNote>> = {};
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-audio-api/src/core/BaseAudioContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export default class BaseAudioContext {
}

async decodeAudioDataSource(sourcePath: string): Promise<AudioBuffer> {
// Remove the file:// prefix if it exists
if (sourcePath.startsWith('file://')) {
sourcePath = sourcePath.replace('file://', '');
}

const buffer = await this.context.decodeAudioDataSource(sourcePath);

return new AudioBuffer(buffer);
Expand Down