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

Stream chunks with socket.io #2

Open
cmarrero01 opened this issue Mar 2, 2015 · 0 comments
Open

Stream chunks with socket.io #2

cmarrero01 opened this issue Mar 2, 2015 · 0 comments

Comments

@cmarrero01
Copy link

Hi, with this package, I can make a streaming of mp3 file with socket.io??...

Something like this using your example file

var fs = require("fs"),
    io = require('socket.io')(),
    util = require("util"),
    mp3Parser = require("mp3-parser"),
    toArrayBuffer = function (buffer) {
        var bufferLength = buffer.length, i = 0,
            uint8Array = new Uint8Array(new ArrayBuffer(bufferLength));

        for (; i < bufferLength; ++i) { uint8Array[i] = buffer[i]; }
        return uint8Array.buffer;
    };

io.on('connection',function(socket){
socket.on('audio',function(data){
fs.readFile(data.pathToMp3, function (error, buffer) {
    if (error) {
        console.log("Oops: " + error);
        process.exit(1);
    }
    buffer = new DataView(toArrayBuffer(buffer));

    var lastFrame = mp3Parser.readLastFrame(buffer),
        tags = mp3Parser.readTags(buffer);


//how i send the chuck to the server? socket.send('chunk',tags)??

});
});
});
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