Compare commits

..

No commits in common. 'main' and 'install-script' have entirely different histories.

@ -1,32 +0,0 @@
# Raspberry pi video player
## How to install
1. Install Raspberry Pi Imager on your local computer from <https://www.raspberrypi.com/software/>
![Install Raspberry Pi Imager](/docs/install-imager.png)
1. Select `Raspberry Pi OS (64-bit)` in Pi Imager
![Select Pi Os](/docs/pi-os.png)
1. Configure Wifi details and `pi` user credentials using the settings in the imager.
![Imager Settings](/docs/imager-settings.png)
1. Flash the SD card
1. Insert it into the Pi and boot it up.
1. Run the following command on the Pi either via ssh or in the terminal from the desktop
```bash
curl https://git.bpfilip.dk/fbp/video-player/raw/branch/main/install.sh | bash
```
1. Access the web interface by typing the ip address of the pi in a web browser followed by the port `:8080`. Fx:
```
http://192.168.25.219:8080
```

@ -1,4 +0,0 @@
[Desktop Entry]
Type=Application
Name=Clock
Exec=sudo systemctl start video-player2.service

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

@ -17,7 +17,7 @@ app.use(express.static('public'));
let videoDirs = [ let videoDirs = [
'./public/videos', './public/videos',
'/media/pi', '/media/pi/USB',
'/video' '/video'
]; ];
@ -42,76 +42,46 @@ app.get('/videos', (req, res) => {
const list = []; const list = [];
for (const dir of videoDirs) { for (const dir of videoDirs) {
try { fs.readdirSync(dir, { recursive: true }).forEach(fileName => {
if (!fs.existsSync(dir)) { if (!fileEndings.includes(path.extname(fileName))) {
continue; return;
} }
fs.readdirSync(dir, { recursive: true }).forEach(fileName => { const file = {
if (!fileEndings.includes(path.extname(fileName))) { name: fileName,
return; path: path.resolve(dir, fileName)
} };
const file = { list.push(file);
name: fileName, });
path: path.resolve(dir, fileName)
};
list.push(file);
});
}
catch (error) {
console.error(error);
}
} }
res.json(list); res.json(list);
}); });
let process = null; let process = null;
let mayRestart = false;
// if (fs.existsSync('/tmp/video')) {
// const initialVideo = fs.readFileSync('/tmp/video');
// startVideo(initialVideo);
// }
function startVideo(path) {
process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', path]);
process.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
process.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
process.on("exit", () => {
if (!mayRestart) {
startVideo(path);
}
});
}
fs.mkdirSync('/video', { recursive: true });
app.post('/play', (req, res) => { app.post('/play', (req, res) => {
if (process) { if (process) {
mayRestart = true;
process.kill(); process.kill();
mayRestart = false;
} }
let video = req.query.video; let video = req.query.video;
console.log(video); console.log(video);
if (video.startsWith('/media/pi')) { if (video.startsWith('/media/pi/USB')) {
fs.copyFileSync(video, path.join('/video/', path.basename(video))); fs.copyFileSync(video, path.join('/tmp/', path.basename(video)));
video = path.join('/video/', path.basename(video)) video = path.join('/tmp/', path.basename(video))
} }
fs.writeFileSync('/tmp/video', video); process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', video], { stdio: 'overlapped' });
process.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
startVideo(video); process.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
res.json({ status: 'ok' }); res.json({ status: 'ok' });
}); });
@ -125,17 +95,11 @@ 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/');
req.files.file.mv(uploadPath + "video.mp4", function (err) { req.files.file.mv(uploadPath + req.files.file.name, function (err) {
if (err) { if (err) {
return res.status(500); return res.status(500);
} }
}); });
try {
require('child_process').spawn('sudo', ['systemctl', 'restart', 'video-player2.service']);
} catch (error) {
console.error(error);
}
res.redirect('/'); res.redirect('/');
}); });

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
cd ~ cd /home/pi
# Install the required packages # Install the required packages
sudo apt update -y sudo apt update -y
@ -8,17 +8,13 @@ sudo apt install -y git curl wget nodejs npm samba samba-common-bin
git clone https://git.bpfilip.dk/fbp/video-player.git git clone https://git.bpfilip.dk/fbp/video-player.git
sudo chown -R steady:steady ~/video-player pushd /home/pi/video-player
pushd ~/video-player
git pull
npm install npm install
# Create the samba share # Create the samba share
sudo mkdir -p /video sudo mkdir -p /video
sudo chown -R steady:steady /video sudo chown -R pi:pi /video
sudo chmod -R 777 /video sudo chmod -R 777 /video
cat smb.conf | sudo tee -a /etc/samba/smb.conf cat smb.conf | sudo tee -a /etc/samba/smb.conf
@ -26,14 +22,7 @@ cat smb.conf | sudo tee -a /etc/samba/smb.conf
sudo systemctl restart smbd sudo systemctl restart smbd
sudo cp video-player.service /etc/systemd/system/video-player.service sudo cp video-player.service /etc/systemd/system/video-player.service
sudo cp video-player2.service /etc/systemd/system/video-player2.service
sudo systemctl daemon-reload
sudo systemctl enable video-player.service sudo systemctl enable video-player.service
sudo systemctl disable video-player2.service sudo systemctl start video-player.service
sudo systemctl restart video-player.service
sudo systemctl restart video-player2.service
mkdir ~/.config/autostart
cp clock.desktop ~/.config/autostart/clock.desktop
popd popd

@ -4,22 +4,8 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PI Video Player</title> <title>PI Video Player</title>
<style>
#videos {
display: flex;
flex-wrap: wrap;
justify-content: center;
flex-direction: column;
width: fit-content;
margin: 0 auto;
}
#videos button {
margin: 2px;
}
</style>
</head> </head>
<body> <body>
<h1>Upload a file and it should start playing</h1>
<form ref='uploadForm' <form ref='uploadForm'
id='uploadForm' id='uploadForm'
action='/upload' action='/upload'

@ -1,5 +1,5 @@
[video] [video]
path = /video path = /path/to/video/folder
writable = yes writable = yes
guest ok = yes guest ok = yes
create mask = 0777 create mask = 0777

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

@ -1,11 +0,0 @@
[Unit]
Description=Video Player
[Service]
WorkingDirectory=/home/steady/video-player
ExecStart=ffplay -fs -loop 2147483647 /home/steady/video-player/public/videos/video.mp4
Environment=DISPLAY=:0
Environment=AUDIODEV="hw:2,0"
User=1000
Group=1000
Restart=always
Loading…
Cancel
Save