react-native-tiny-wavpack-decoder
Version:
Tiny WavPack Decoder for React Native
38 lines (37 loc) • 1.15 kB
JavaScript
;
import NativeTinyWavPackDecoder from "./NativeTinyWavPackDecoder.js";
import { NativeModules, NativeEventEmitter } from 'react-native';
const {
TinyWavPackDecoderModule
} = NativeModules;
const emitter = new NativeEventEmitter(TinyWavPackDecoderModule);
const TinyWavPackDecoder = {
decode: async (inputPath, outputPath, options = {}) => {
const {
maxSamples = -1,
bitsPerSample = 16
} = options;
if (![8, 16, 24, 32].includes(bitsPerSample)) {
throw new Error('bitsPerSample must be 8, 16, 24, or 32');
}
return NativeTinyWavPackDecoder.decodeWavPack(inputPath, outputPath, maxSamples, bitsPerSample);
},
/**
* Subscribe to native progress updates
*/
addProgressListener: callback => {
return emitter.addListener('onProgressUpdate', event => {
if (typeof event?.progress === 'number') {
callback(event.progress);
}
});
},
/**
* Remove all native listeners for progress updates
*/
removeAllListeners: () => {
emitter.removeAllListeners('onProgressUpdate');
}
};
export default TinyWavPackDecoder;
//# sourceMappingURL=index.js.map