Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading base64 source #18

Open
peterbe opened this issue May 7, 2018 · 0 comments
Open

Loading base64 source #18

peterbe opened this issue May 7, 2018 · 0 comments

Comments

@peterbe
Copy link

peterbe commented May 7, 2018

This works:

import play from "audio-play";
import load from "audio-loader";

load("./sounds/coin.mp3").then(audioBuffer => {
  play(audioBuffer);
});

But I want to encode the AudioBuffer to a string (so it can be stored in localStorage next time) and back again.

This does NOT work:

// Copied from  audio-loader/test/support/utils.js
function arrToBase64Audio(arr) {
  var data = new Buffer(arr).toString("base64");
  return "data:audio/mp3;base64," + data;
}

load("./sounds/coin.mp3").then(audioBuffer => {
  console.log(audioBuffer);
  const asString = arrToBase64Audio(audioBuffer);
  console.log(asString);
  console.log(asString.length);
  load(asString).then(ab => {
    //console.log(ab);
    play(ab);
  });
});

It says:

The buffer passed to decodeAudioData contains an unknown content type.

screen shot 2018-05-07 at 5 01 07 pm

*Firefox*

screen shot 2018-05-07 at 5 02 22 pm

*Chrome*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant