2

I'm attempting to use Aurora.JS to play audio received from a streaming AAC-encoded source. I'm successfully pulling chunked data, and trying to feed it into a custom emitter, but no audio is actually playing.

Maybe I'm missing something very simple. Here's a sample of what I'm trying to do:

http://jsfiddle.net/Rc6Su/4/

(You're almost certainly gonna get a CORS error when hitting "Play" because the source is cross-domain. The only way I can easily get around that is using this plugin: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en)

Before you mention it, this is going into a PhoneGap app and so the cross-domain issue isn't going to be a problem.

The problem code is somewhere in here:

var aurora_source = null;
var player = null;
function make_noise(chunk) {
    var uarr = (function (chunk) {
        var buf = new ArrayBuffer(chunk.length * 2); // 2 bytes for each character
        var bufView = new Uint8Array(buf);
        for (var i=0, strLen=chunk.length; i<strLen; i++) {
            bufView[i] = chunk.charCodeAt(i);
        }
        return buf;
    })(chunk);
    var abData = new AV.Buffer(uarr);

    if (!aurora_source) {
        var MySource = AV.EventEmitter.extend ({
            start   : function () {
                this.emit('data', abData);
            },
            pause   : function () {
            },
            reset   : function () {
            }
        });
        aurora_source = new MySource();
        asset = new AV.Asset(aurora_source);
        player = new AV.Player(asset);
        player.play();
    } else {
        $("#debug").append("emit data");
        $("#debug").append("\n");
        aurora_source.emit('data', abData);
    }
}
dertkw
  • 7,798
  • 5
  • 37
  • 45
cedmans
  • 302
  • 1
  • 7

1 Answers1

0

Could not get audio to play, but found at least that

bufView[i] = chunk.charCodeAt(i);

may have to be replaced by

bufView[i] = chunk.charCodeAt(i) & 0xff;

see What does charCodeAt(...) & 0xff accomplish?

hope it helps.

Community
  • 1
  • 1
astooooooo
  • 362
  • 2
  • 13