2

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.

nekumelon
  • 21
  • 4
  • Possibly https://stackoverflow.com/questions/47285624/safari-blocks-play-on-video-despite-being-called-from-click-event or https://stackoverflow.com/questions/51485755/how-get-url-createobjecturlblob-to-work-in-safari – fdcpp Oct 26 '21 at 06:12
  • I've already tried both of those, neither worked. Thanks for trying though. – nekumelon Oct 27 '21 at 05:54
  • Can you add a minimal self-contained, reproducible example? This will avoid anyone having to do heavy lifting to recreate this issue. Ideally it should be minimal so strip out everything you can that doesn’t relate to the error. – fdcpp Oct 27 '21 at 06:16
  • https://pastebin.com/wFJga4jA - Here's the raw code. http://soundtest.orgfree.com/ - Here's the live code. – nekumelon Oct 28 '21 at 02:59
  • what was the issue? – Diego Ponciano Jul 08 '23 at 18:14

0 Answers0