peaks.js
peaks.js copied to clipboard
Is it possible to support remote recording ?
Right now it seems peaks.js only support local wav files. If I set src with a remote online recording, the peaks.js will throw an error: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Is your web server setting an Access-Control-Allow-Origin
header in response to requests for the audio file or waveform data?
@chrisn I already set that. It says the server doesn't support CROS. What I am curious is I can sent a http request to download the remote wav files. But for peaks.js . I read the source code. It sends a XMLHttpRequest to get the wav file Data, the error occurs. Code as below:
Waveform.prototype.getRemoteData = function (options) {
var self = this;
var xhr = new XMLHttpRequest();
var uri = null;
var requestType = null;
var builder = null;
if (options.dataUri) {
if (typeof options.dataUri === 'string') {
var dataUri = {};
dataUri[options.dataUriDefaultFormat || 'json'] = options.dataUri;
options.dataUri = dataUri;
}
if (typeof options.dataUri === 'object') {
[
'ArrayBuffer',
'JSON'
].some(function (connector) {
if (window[connector]) {
requestType = connector.toLowerCase();
uri = options.dataUri[requestType];
return Boolean(uri);
}
});
}
}
if (!options.dataUri && options.audioContext) {
requestType = 'arraybuffer';
uri = options.mediaElement.currentSrc || options.mediaElement.src;
builder = webaudioBuilder;
}
if (!uri) {
throw new Error('Unable to determine a compatible dataUri format for this browser.');
}
xhr.open('GET', uri, true);