openradio
Version:
A simple live streaming library written in JavaScript with ffmpeg.
38 lines (33 loc) • 1.08 kB
JavaScript
const openradio = require("openradio");
// As a regular TS does not works well in Browser,
// Stream it with specific media player, Like mpv or vlc.
const radio = openradio.video();
const http = require("http");
const fs = require("fs");
let repeater = openradio.repeater(radio);
http
.createServer((req, res) => {
res.setHeader("content-type", "video/ts");
repeater(res);
})
.listen(3000);
var { extname } = require("path");
var list = fs
.readdirSync("./Video", { withFileTypes: true })
.filter(function (item) {
// Make it returns true
return (
item.isFile &&
(extname(item.name) === ".mp4" ||
extname(item.name) === ".mkv" ||
extname(item.name) === ".webm" ||
extname(item.name) === ".3gp" ||
extname(item.name) === ".ogv")
);
})
.map((videoItem) => videoItem.name);
// Fetch & Play song randomly fron Video Directory!
radio.play(`./Video/${list[Math.floor(Math.random() * list.length)]}`);
radio.on("finish", () => {
radio.play(`./Video/${list[Math.floor(Math.random() * list.length)]}`);
});