-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
58 lines (39 loc) · 1.24 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// command to run: omxplayer -b -o hdmi --loop --no-osd video.mp4
var express = require('express');
var formidable = require('express-formidable');
var fs = require('fs');
var configuration = {
omxPlayerParams: ['--loop', '--no-osd', '-o', 'hdmi', '-b']
}
var OMXPlayer = require('omxplayer')
var omxplayer = new OMXPlayer(configuration);
var mediaFolder = "media"
var app = express();
app.use(formidable());
app.post('/upload', (req, res) => {
fs.rename(req.files.upload.path, __dirname + "/media/" + req.files.upload.name, function(err) {
console.log("Moved..?")
newVideo(req.files.upload.name)
});
res.end("Got it!")
});
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
})
fs.readFile('./currentvid.txt', (err, data) => {
if (err) return;
console.log(String(data))
newVideo(String(data))
})
function newVideo(name) {
omxplayer.stop();
setTimeout(() => {
console.log("Playing file " + mediaFolder + "/" + name)
omxplayer.start(mediaFolder + "/" + name, function(error) {
console.log(error)
});
//write to file so it will reload next time
fs.writeFile('./currentvid.txt', name, console.log)
}, 1000)
}
app.listen(3000)