Home > Net >  Cordova and Tone.js "Error: buffer is either not set or not loaded" when i try to load an
Cordova and Tone.js "Error: buffer is either not set or not loaded" when i try to load an

Time:01-17

maybe you can give me a hand, I've been looking for all information, in order to solve this problem of mine, but nothing, I can't use the player with cordova ...

in practice I can't load mp3 files, whether they are both locally and remotely, I always get this error: "Error: buffer is either not set or not loaded", the files in the path are there.

I tried using Tone's oscilloscope to see if I was having trouble loading Tone, but this works fine.

Could it depend on some authorization, particular that I might be missing ?.

For example using cordova media plugin I can reproduce the audio, but I need to use Tonejs.

Do you have any ideas, what this might depend on. or what could I try to do? ...

even this simple example, after the device ready does not go:

const player = new Tone.Player("https://tonejs.github.io/audio/berklee/gong_1.mp3") .toDestination();
   Tone.loaded().Then(() => {
       player.start ();
   });

You who have already worked with Tone and Cordova, give me hope that it can be used in some way, let me know if you have any ideas thanks in advance!

--- UPDATE:

Currently when the app starts, I behave like this (I state that it is a porting of the code developed for a website and that everything works correctly loading it, etc.):

let myLoader_File = function functionOne(test) {
    var androidFixPath = cordova.file.applicationDirectory
    console.log("Entered function");
    return new Promise((resolve, reject) => {
    let CaricatorePlayers = new Tone.Players({
            Beep: androidFixPath   "sample/Beep.mp3",
            Clave: androidFixPath   "sample/Clave.mp3",
        }).toDestination();
        resolve(
            CaricatorePlayers
            //"ok tutti i file sono stati caricati!"
        );
        reject("si è verificato un errore!");
    });
};


function onDeviceReady() {
    $('#fade-wrapper-flash').fadeOut(1000);
    $('#fade-wrapper').fadeIn();

    //attach a click listener to a start button
    document.querySelector('#fade-wrapper').addEventListener('click', async () => {
        await Tone.start();
        console.log('audio is ready');
        myLoader_File().then((res) => {
            console.log(`The function recieved with value ${res}`)
            MultiPlayers = res;
            console.log(MultiPlayers)
            try {
                // Play
                MultiPlayers.player("Beep").start();
                $('#fade-wrapper').fadeOut();
                preLoad();
            } catch (error) {
                console.log(error);
                console.log("IN ERRORE RICARICO");
            }
        }).catch((error) => {
            console.log(`Handling error as we received ${error}`);
            console.log("IN ERRORE RICARICO");
            $('#fade-wrapper').fadeIn();
        });
    });
}

CodePudding user response:

I posted an answer, here, which also solves this problem.

I don't know if the solution is the only possible way, or the best, in order to access the folders locally, I made these changes to the call. Using an XMLHttpRequest object which can be used, to request data from a web server, I got a Blob object, which I then passed to the Tone player.

  •  Tags:  
  • Related