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.

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
ANISUNDAR
  • 787
  • 5
  • 12
  • 28
  • 2
    Possible duplicate of [converting audio file to base64 using javascript](http://stackoverflow.com/questions/31161897/converting-audio-file-to-base64-using-javascript) – Anik Islam Abhi Mar 28 '17 at 04: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 – Jaromanda X Mar 28 '17 at 04:41
  • Thanks for ur reply.This audio file played on mobile very delayed.any other way to fix this pblm. – ANISUNDAR Mar 28 '17 at 04:49

1 Answers1

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));
    }
Parth Ghiya
  • 6,929
  • 2
  • 30
  • 37
  • Thanks for ur reply.This audio file played on mobile very delayed.any other way to fix this pblm – ANISUNDAR Mar 28 '17 at 04:50
  • @ANISUNDAR thats complete different question altogether, you will need to use something from https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API – Parth Ghiya Mar 28 '17 at 04:54