Skip to content

Stream chunks with socket.io #2

Description

@cmarrero01

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)??

});
});
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions