Operating System: Windows to Apple iOS
Device: PC to iPhone 6, iPhone XS, iPhone XR, iPhone 11, iPhone 6S
Browser: Safari, Google Chrome
Errors: [native code]:1 Unhandled Promise Rejection: NotSupportedError: The operation is not supported.
[native code]:1 Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
Code:
let started = false;
let audio = new Audio();
audio.src = "data:audio/mpeg;base64,SUQzBAAAAAABEVRYWFgAAAAtAAADY29tbWVudABCaWdTb3VuZEJhbmsuY29tIC8gTGFTb25vdGhlcXVlLm9yZwBURU5DAAAAHQAAA1N3aXRjaCBQbHVzIMKpIE5DSCBTb2Z0d2FyZQBUSVQyAAAABgAAAzIyMzUAVFNTRQAAAA8AAANMYXZmNTcuODMuMTAwAAAAAAAAAAAAAAD/80DEAAAAA0gAAAAATEFNRTMuMTAwVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/zQsRbAAADSAAAAABVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/zQMSkAAADSAAAAABVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV";
...
class FrequencyData {
constructor() {
this.audioContext = null;
this.source = null;
this.analyser = null;
}
getFrequencies() {
if (!this.audioContext) {
this.audioContext = new window.AudioContext();
this.source = this.audioContext.createMediaElementSource(audio);
this.analyser = this.audioContext.createAnalyser();
}
this.source.connect(this.analyser);
this.analyser.connect(this.audioContext.destination);
return [new Uint8Array(this.analyser.frequencyBinCount), this.analyser];
}
}
let frequencyData = new FrequencyData();
window.addEventListener("touchstart", function() { // Allows for audio to be played without needing user interaction every time.
if (!started) {
audio.play();
started = true;
}
});
...
webSocket.onmessage = function(event) {
let message = event.data;
audio.src = "";
...
audio.src = "data:audio/mp3;base64," + message;
audio.play();
render();
...
The errors occur at the same time. I tested them on my iPhone and on hosted iPhones on browserstack so I could view the developer console. The audio is being sent through a websocket being hosted on my PC and is sent to the client which are the phones. It worked while testing it on other PCs. The audio is being sent as a base64 string and are mp3 files.