Невозможно воспроизвести Html5 Audio с помощью URL-адреса BLOB-объекта из буфера массива. - PullRequest
0 голосов
/ 16 января 2019

Я пытаюсь прочитать аудиофайл с сервера и воспроизвести аудио в формате html5. Я могу заставить его работать должным образом в localhost без каких-либо проблем.

Но на сайте это не работает.

    var xhr = new XMLHttpRequest();
    xhr.open('POST', './getaudio', true);
    xhr.responseType = 'arraybuffer';
    xhr.onload = function(e) {
    // response is unsigned 8 bit integer
    var responseArray = new Uint8Array(this.response); 

    var blob = new Blob([responseArray], {type : 'audio/ogg'});
    var blobUrl = URL.createObjectURL(blob);
    source.src = blobUrl;
    audio.load(); //call this to just preload the audio without playing
    audio.play(); //call this to play the song right away
    };
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.send('id=' + id1);
...