Play base64 audio string from Azure Blob service REST api with Javascript/Phonegap -


im having trouble playing audio file (.aac) stored bae64 encoded string in azure blob storage javascript.

i have following scenario:

  • a mobile app (phonegap) records audio .aac file , stores in localstorage. file same small (<250kb)
  • the file get's converted base64 encoded string , uploaded blob storage account through jquery ajax call (see upload_code) below using blob service rest api. see this page details on blob service rest api.
  • when download file manually through browser can see base64 encoded string starts witch "data:application/octet-stream;base64,aaaa....."

upload_code snippet:

$.ajax({   url: url,   type: "put",   data: requestdata,   processdata: false,   beforesend: function (xhr)                {                xhr.setrequestheader('x-ms-blob-type', 'blockblob');                },                trycount: 0,                retrylimit: number_of_retries,                success: successcallback,                error: errorcallback    }); 

at point well. stuck @ playback of file storage api. can access file through url want user able listen uploaded audio.

i've been thinking along following solutions haven't been able working yet:

a. use phonegap media class , pass in url base64 encoded string , start playing (streaming) audio.

b. download base64 string, convert audio file in javascript , start playback.

c. upload file in blob storage actual aac file instead of base64 encoded string playback starts when opening url through, example, browser.

d. ... ?

in way can turn of these scenario's working solution?

i have solved uploading file byte[] instead of base64 encoded string. file get's stored .aac audio file in blob storage , can played directly storage.

for uploading used following code:

var reader = new filereader(); reader.onloadend = function (evt) {  if (evt.target.readystate === filereader.done) { // done == 2      var retry_timeout_seconds = 5;     var number_of_retries = 3;      var requestdata = new uint8array(evt.target.result);      $.ajax({              url: url,              type: "put",              data: requestdata,              processdata: false,              beforesend: function (xhr) {                                 xhr.setrequestheader('x-ms-blob-type', 'blockblob');                             },              trycount: 0,              retrylimit: number_of_retries,              success: function (data, status) {                                 console.log(status);                             },               error: function (xhr, desc, err) {                       if (xhr.status === 403) {                                     console.log("access denied, assigned upload  time has been exeeded");                                 } else {                                     this.trycount += 1;                                     if (this.trycount <= this.retrylimit) {                                         console.log("retrying transmission");                                         settimeout($.ajax(this), retry_timeout_seconds * 1000);                                         return;                                     }                                 }                                 console.log(desc);                                 console.log(err);                             }                         });                     }                 };    // read file byte[]    reader.readasarraybuffer(dbfile); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -