0

I have an audio Link:

var au='https://firebasestorage.googleapis.com/v0/b/test-46a7f.appspot.com/o/Audio.mp3?alt=media&token=a4fa9b18-ab70-4bbc-8ae1-21639d411035'; 

I need to convert the audio to base64, because its play on mobile devices with a very big delay.

3
  • 2
    Possible duplicate of converting audio file to base64 using javascript Commented Mar 28, 2017 at 4:38
  • If you are thinking of doing this in a browser, the main issue I see is that the server wont let you access the raw audio Commented Mar 28, 2017 at 4:41
  • Thanks for ur reply.This audio file played on mobile very delayed.any other way to fix this pblm. Commented Mar 28, 2017 at 4:49

1 Answer 1

1

Please see working plunkr https://plnkr.co/edit/PFfebmnqH0eQR9I92v0G?p=preview, Its in Angular 2

Core Logic is JS method : HTML

<input type="file" id="filePicker" (change)="handleFileSelect($event)"> 

JavaScript:

handleFileSelect(evt){
      var files = evt.target.files;
      var file = files[0];

    if (files && file) {
        var reader = new FileReader();

        reader.onload =this._handleReaderLoaded.bind(this);

        reader.readAsBinaryString(file);
    }
  }



 _handleReaderLoaded(readerEvt) {
     var binaryString = readerEvt.target.result;
            this.base64textString= btoa(binaryString);
            console.log(btoa(binaryString));
    }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for ur reply.This audio file played on mobile very delayed.any other way to fix this pblm
@ANISUNDAR thats complete different question altogether, you will need to use something from developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.