diff --git a/index.js b/index.js old mode 100644 new mode 100755 index a5ae43b..3434744 --- a/index.js +++ b/index.js @@ -74,7 +74,8 @@ if (fs.existsSync('/selectedvideo')) { } function startVideo(path) { - process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', path]); + + const newProcess = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', path]); // process.stdout.on('data', (data) => { // console.log(`stdout: ${data}`); @@ -84,11 +85,23 @@ function startVideo(path) { // console.error(`stderr: ${data}`); // }); - process.on("exit", () => { - if (!mayRestart) { - startVideo(path); + // newProcess.on("exit", (code) => { + // if (!mayRestart && code !== 0) { + // startVideo(path); + // } + // }); + + setTimeout(() => { + if (process) { + process.kill(); } - }); + // newProcess.on("exit", (code) => { + // if (!mayRestart && code !== 0 && process === newProcess) { + // startVideo(path); + // } + // }); + process = newProcess; + }, 5000); } fs.mkdirSync('/video', { recursive: true }); @@ -116,6 +129,18 @@ app.post('/play', (req, res) => { res.json({ status: 'ok' }); }); +app.post("/select", (req, res) => { + let video = req.query.video; + fs.writeFileSync('/overlayvideo', video); + res.json({ status: 'ok' }); +}); + +app.post("/playoverlay", (req, res) => { + let video = fs.readFileSync('/overlayvideo'); + require('child_process').spawn('ffplay', ['-fs', '-autoexit', '-hide_banner', '-loglevel', 'error', video]); + res.json({ status: 'ok' }); +}); + app.post('/upload', function (req, res) { if (!req.files || Object.keys(req.files).length === 0) { diff --git a/public/index.html b/public/index.html old mode 100644 new mode 100755 index 8ceccff..26ba665 --- a/public/index.html +++ b/public/index.html @@ -5,7 +5,7 @@