other
Filip Borum Poulsen 1 year ago
parent a0f3153c26
commit dcdf469996

@ -68,21 +68,21 @@ app.get('/videos', (req, res) => {
let process = null; let process = null;
let mayRestart = false; let mayRestart = false;
// if (fs.existsSync('/tmp/video')) { if (fs.existsSync('/selectedvideo')) {
// const initialVideo = fs.readFileSync('/tmp/video'); const initialVideo = fs.readFileSync('/selectedvideo');
// startVideo(initialVideo); startVideo(initialVideo);
// } }
function startVideo(path) { function startVideo(path) {
process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', path]); process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', path]);
process.stdout.on('data', (data) => { // process.stdout.on('data', (data) => {
console.log(`stdout: ${data}`); // console.log(`stdout: ${data}`);
}); // });
process.stderr.on('data', (data) => { // process.stderr.on('data', (data) => {
console.error(`stderr: ${data}`); // console.error(`stderr: ${data}`);
}); // });
process.on("exit", () => { process.on("exit", () => {
if (!mayRestart) { if (!mayRestart) {
@ -109,7 +109,7 @@ app.post('/play', (req, res) => {
video = path.join('/video/', path.basename(video)) video = path.join('/video/', path.basename(video))
} }
fs.writeFileSync('/tmp/video', video); fs.writeFileSync('/selectedvideo', video);
startVideo(video); startVideo(video);
@ -123,9 +123,12 @@ app.post('/upload', function (req, res) {
} }
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file // The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
const uploadPath = path.join(__dirname, '/public/videos/'); // const uploadPath = path.join(__dirname, '/public/videos/');
const uploadPath = "/video";
req.files.file.mv(uploadPath + "video.mp4", function (err) { console.log(req.files.file);
req.files.file.mv(path.join(uploadPath, req.files.file.name), function (err) {
if (err) { if (err) {
return res.status(500); return res.status(500);
} }
@ -138,4 +141,4 @@ app.post('/upload', function (req, res) {
} }
res.redirect('/'); res.redirect('/');
}); });

@ -3,12 +3,12 @@ Description=Video Player
After=multi-user.target After=multi-user.target
[Service] [Service]
WorkingDirectory=/home/steady/video-player WorkingDirectory=/home/pi/video-player
ExecStart=node /home/steady/video-player/index.js ExecStart=node /home/pi/video-player/index.js
Environment=DISPLAY=:0 Environment=DISPLAY=:0
User=1000 User=1000
Group=1000 Group=1000
Restart=always Restart=always
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

@ -2,10 +2,10 @@
Description=Video Player Description=Video Player
[Service] [Service]
WorkingDirectory=/home/steady/video-player WorkingDirectory=/home/pi/video-player
ExecStart=ffplay -fs -loop 2147483647 /home/steady/video-player/public/videos/video.mp4 ExecStart=ffplay -fs -loop 2147483647 $(cat /selectedvideo)
Environment=DISPLAY=:0 Environment=DISPLAY=:0
Environment=AUDIODEV="hw:2,0" Environment=AUDIODEV="hw:2,0"
User=1000 User=1000
Group=1000 Group=1000
Restart=always Restart=always

Loading…
Cancel
Save