peaks.js icon indicating copy to clipboard operation
peaks.js copied to clipboard

Is it possible to support remote recording ?

Open seaskymonster opened this issue 7 years ago • 2 comments

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.

seaskymonster avatar Feb 08 '18 20:02 seaskymonster

Is your web server setting an Access-Control-Allow-Origin header in response to requests for the audio file or waveform data?

chrisn avatar Feb 08 '18 21:02 chrisn

@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);

seaskymonster avatar Feb 08 '18 22:02 seaskymonster