Max Amini
Max Amini

Reputation: 31

Is it possible that stream mp3 as blob?

I wrote a simple code that PHP sends mp3 data as blob and in client side (JS) html5 audio object plays it but the problem is : first whole of file should be fetched and then audio can be played.

function blob(uri){

    $.ajax({

        type: "POST",
        url:uri,


        success:function(result){

            let binary = convertDataURIToBinary(result);
            let blob = new Blob([binary], {type : 'audio/mp3'});
            let uri= URL.createObjectURL(blob);

            audio.src = uri;
            audio.load();

            audio.play().then(

            r => {
                
                //do something
            }

            ).catch((error) => {

                checkInternet();
            });
    

        }});

}

Blockquote

So my question : is it possible that I send data as blob and before sending whole file, audio plays? or I have to implement a client js player myself to do that?

Upvotes: 0

Views: 45

Answers (0)

Related Questions