Giter Club home page Giter Club logo

Comments (4)

asherawelan avatar asherawelan commented on July 21, 2024

Here's the images from my console dump...
screen shot 2013-12-02 at 20 16 08

from aurora.js.

secumundo avatar secumundo commented on July 21, 2024

Same here. Though I am not using websockets but xhr to get chunks, I pretty much followed the same trail.

<script type="text/javascript" src="exjs/aurora/aurora.js"></script>
<script type="text/javascript" src="exjs/aurora/mp3.js"></script>

var aurora_source = null;

/* Chunk is a part of an MP3 */

while(1)
{
         chunk = loadAChunk();
         makeNoise(Chunk);
}

function makeNoise(chunk)
{
var uarr = makeUint8Array(chunk);
var abData = new AV.Buffer(uarr);

if (!aurora_source)     {
                var MySource = AV.EventEmitter.extend ({
                        start: function() {
                                console.log("start data");
                                this.emit('data',abData);
                                },
                        pause: function() {
                                // nope
                                },
                        reset: function() {
                                // nope
                                }
                        });
                aurora_source = new MySource();
                asset = new AV.Asset(aurora_source);
                player = new AV.Player(asset);
                player.play();
} else {
                aurora_source.emit('data',abData);
                }

Result: No audio but an error: ailed to load script: blob:6d445111-e01a-4701-90ef-351bf8689348 (nsresult = 0x805e0006)

The corresponding code in aurora.js:

url = AV.Buffer.makeBlobURL("setInterval(function() { postMessage('ping'); }, " + interval + ");");
    if (url == null) {
      return setInterval(fn, interval);
    }
    worker = new Worker(url);

from aurora.js.

itrcz avatar itrcz commented on July 21, 2024

after some testing, I figured out that it actually works but not with all files, ABR and CBR with rate more then 64k isnt playing while buffering, after buffering is complite and if call play() song will play.
VBR situation is better, works with good quality on 441000 sampling, 48000 the situation same as CBR.
also for some reason player isnt working on iOS safari/chrome, buffering going well, but no playback.
with android - almost the same, only firefox on android able to play it but with big delay and UI getting slow while playing song.

here is server side

var audioFolder = __dirname + '/audio/';

wss.on('connection', function(ws) {

var audioPath, audioStream, createFileStream;

audioStream = null;
audioPath = audioFolder + '10.mp3';

fs.stat(audioPath, function(err, stats) {
    if (err) {
        return ws.send(JSON.stringify({error: 'Could not retrieve file.'}));
    } else {
        ws.send(JSON.stringify({
            fileSize: stats.size
        }));
        return createFileStream();
    }
});  

var createFileStream = function() {

    audioStream = fs.createReadStream(audioPath);

    audioStream.on('data', function(data) {
        ws.send(data, {binary: true});
    });
    audioStream.on('end', function() {
        ws.send(JSON.stringify({end: true}));
    });
};
});

and the client-side

var host = window.document.location.host.replace(/:.*/, '');
var AudioSource = AV.EventEmitter.extend ({

start: function() {
    var source = this;

    source.bytesLoaded = 0;
    var ws = new WebSocket('ws://' + host + ':3000');
    ws.binaryType = "arraybuffer";

    ws.onmessage = function (event) {
        var data = event.data;

        if ("string" != typeof data) {

            data = new AV.Buffer(new Uint8Array(data));
            source.bytesLoaded += data.length;

            if (data) {
                 source.emit("progress", 100 * (source.bytesLoaded / source.length));
            }
            source.emit("data", data);
        } else {
            data = JSON.parse(data);
            if (null != data.fileSize) {
                source.length = data.fileSize;
            } else if (null != data.error) {
                source.emit("error", data.error);
            } else if (data.end) {
                source.emit("end");                  
            } else {
                return;
            }
        }
    };

},
pause: function() {},
reset: function() {},
});

var buffer          = new AudioSource();
var asset           = new AV.Asset(buffer);
var player          = new AV.Player(asset);
player.play();

from aurora.js.

devongovett avatar devongovett commented on July 21, 2024

Closing due to inactivity.

from aurora.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.