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 = [
'./public/videos',
'/media/pi',
'/media/pi/USB',
'/video'
];
@ -42,76 +42,46 @@ app.get('/videos', (req, res) => {
const list = [];
for (const dir of videoDirs) {
try {
if (!fs.existsSync(dir)) {
continue;
fs.readdirSync(dir, { recursive: true }).forEach(fileName => {
if (!fileEndings.includes(path.extname(fileName))) {
return;
}
fs.readdirSync(dir, { recursive: true }).forEach(fileName => {
if (!fileEndings.includes(path.extname(fileName))) {
return;
}
const file = {
name: fileName,
path: path.resolve(dir, fileName)
};
list.push(file);
});
}
catch (error) {
console.error(error);
}
const file = {
name: fileName,
path: path.resolve(dir, fileName)
};
list.push(file);
});
}
res.json(list);
});
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) => {
if (process) {
mayRestart = true;
process.kill();
mayRestart = false;
}
let video = req.query.video;
console.log(video);
if (video.startsWith('/media/pi')) {
fs.copyFileSync(video, path.join('/video/', path.basename(video)));
video = path.join('/video/', path.basename(video))
if (video.startsWith('/media/pi/USB')) {
fs.copyFileSync(video, path.join('/tmp/', 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' });
});
@ -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
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) {
return res.status(500);
}
});
try {
require('child_process').spawn('sudo', ['systemctl', 'restart', 'video-player2.service']);
} catch (error) {
console.error(error);
}
res.redirect('/');
});

@ -1,6 +1,6 @@
#!/bin/bash
cd ~
cd /home/pi
# Install the required packages
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
sudo chown -R steady:steady ~/video-player
pushd ~/video-player
git pull
pushd /home/pi/video-player
npm install
# Create the samba share
sudo mkdir -p /video
sudo chown -R steady:steady /video
sudo chown -R pi:pi /video
sudo chmod -R 777 /video
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 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 disable video-player2.service
sudo systemctl restart video-player.service
sudo systemctl restart video-player2.service
mkdir ~/.config/autostart
cp clock.desktop ~/.config/autostart/clock.desktop
sudo systemctl start video-player.service
popd

@ -4,22 +4,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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>
<body>
<h1>Upload a file and it should start playing</h1>
<form ref='uploadForm'
id='uploadForm'
action='/upload'

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

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