Proinsias
Posts: 28
Joined: Fri Jan 11, 2013 1:06 am
Location: Scotland

Video player - Play on Boot

Fri Oct 19, 2018 9:46 pm

Goal:

RPi 2 connected via hdmi to a TV which starts playing video on boot. Preferably able to run a randomized infinite loop of video files stored locally.
The idea being that switching on the plug to the TV/Pi socket is enough to keep the Pi playing movies indefinitely until power is cut and there is no need for any user input.

My plan was to use Alpine & omxplayer, it's fast light and the live/readonly nature of the install seems ideal where the only interaction is the power going on or off. But after an hour or so last night I'm struggling with the very basics. OMXplayer doesn't seem keen to play more than one file at a time alongside the lack of any random or loop options.

I've had a quick duckduckgo around Kodi, been a while since I used, and couldn't see a simple solution.

Any ideas?

User avatar
topguy
Posts: 5498
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Video player - Play on Boot

Sat Oct 20, 2018 8:50 pm

Welcome to the world of shell/bash scripting.

How to repeatedly pick a file at random from a directory and do something with it.

Code: Select all

#!/bin/bash

while true
do
  filename=$(ls Videos | shuf -n 1)
  ls -l Videos/$filename
  sleep 2
done


Proinsias
Posts: 28
Joined: Fri Jan 11, 2013 1:06 am
Location: Scotland

Re: Video player - Play on Boot [SOLVED]

Sun Oct 21, 2018 10:06 pm

Thank you.

I created randomvideo.sh:

Code: Select all

#!/bin/sh

while true
do
  filename=$(ls /mnt/storage | shuf -n 1)
  omxplayer /mnt/storage/"$filename"
  sleep 2
done
which starts on login called from ~/.profile:

Code: Select all

/home/user/randomvideo.sh
Still working on autologin. I've been trying some examples from /etc/inittab but haven't got it working yet.

*edit*

autologin now working too.
I installed util-linux, which provides agetty, instead of busybox getty & ammended /etc/inittab:

Code: Select all

# Set up a couple of getty's
tty1::respawn:-/sbin/agetty --noclear -a username -n 38400 tty1
tty2::respawn:/sbin/getty 38400 tty2
tty3::respawn:/sbin/getty 38400 tty3
Would be nice to have autologin without needing util-linux/agetty but it is working, which is nice.

User avatar
topguy
Posts: 5498
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Video player - Play on Boot

Mon Oct 22, 2018 10:13 am

I dont know what "Alpine" is, you are not running Raspbian ?

Proinsias
Posts: 28
Joined: Fri Jan 11, 2013 1:06 am
Location: Scotland

Re: Video player - Play on Boot

Fri Jan 11, 2019 8:49 pm

topguy wrote:
Mon Oct 22, 2018 10:13 am
I dont know what "Alpine" is, you are not running Raspbian ?
https://alpinelinux.org/
It's a lovely little distribution. Light & fast, moreso aimed at servers and docker type stuff but can be coaxed into more general usage running the rolling edge branch. I've been really enjoying it on my 10+yr laptop since the summer. The default pi install also runs in RAM which can be useful.

----------

Anyway.....

I now have a pi3 with retropie on it at the moment, which appears to be raspbian/debian 9.6 under the hood.

In an attempt to have looping video on boot as an optional extra on my pi alongside everything else I thought I'd give systemd a shot.

I have a script to play the files:

Code: Select all


#!/bin/sh

while true
do
  filename=$(ls /home/pi/video/movies/ | shuf -n 1)
  omxplayer -r /home/pi/video/movies/"$filename"
  sleep 2
done
and have a systemd service:

Code: Select all

[Unit]
Description=Ambient scenery display
Before=systemd-user-sessions.service

[Service]
TimeoutStartSec=0

ExecStart=/home/pi/scripts/loopvideo.sh
Type=simple
User=pi

ExecStop=/usr/bin/killall omxplayer
User=pi
I can the start the service and it runs just fine with systemctl start omxplayer but if I try to enable the service with systemd I get:

Code: Select all

$ sudo systemctl enable omxplayer
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.
Any idea on how to get systemd to enable this service? I have barely used systemd and it's been a few years at least but figuring if it's managing to start the service I'm not too far from enabling.

Return to “Media centres”