Play Video on Startup of Raspbian on Raspberry Pi

I wanted to be able to play a video on start up of the Raspberry Pi so no human intervention was necessary – you plug in the Pi it boots and plays the selected video(s). This proved a bit tricky in Raspbian so here are the steps required.

1. Create a file and call it playvid.sh put it on the desktop and in a text editor enter the following;

#!/bin/sh

# get rid of the cursor so we don't see it when videos are running
setterm -cursor off																						

VIDEOPATH="/home/pi/vids" 

# you can normally leave this alone
SERVICE="omxplayer"

# now for our infinite loop!
while true; do 
	$SERVICE -r -o hdmi $VIDEOPATH/video_name
	$SERVICE -r -o hdmi $VIDEOPATH/video_name
done

2. Create a file called videostart.desktop and put the following content in the file

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
StartupNotify=true
Name=Play Videos
Comment=Play all videos in /home/pi/vids
Exec=lxterminal --command "/home/pi/Desktop/playvid.sh"
Categories=Application;

3. Put videostart.desktop in /etc/xdg/autostart/

4. Put the videos to play into /home/pi/vids or which ever path you define as the VIDEOPATH variable within playvid.sh which you created in Step 1.

5. Edit playvid.sh (from Step 1) to have the right video names. You can add as many videos as required to the list to play, just copy and paste the following line of code replacing video_name with the full name of the file including the extention (i.e. mp4).

	$SERVICE -r -o hdmi $VIDEOPATH/video_name

6. Simply restart the Raspberry Pi and the videos should start playing.

 

This entry was posted in Raspberry Pi, Raspbian, Uncategorized. Bookmark the permalink.
  • Sam Levin

    How would I work this same script but have it target arbitrary files? I.e. ‘iff a video file exists with any extension, play it.’. It’s an elegant solution but in my case I won’t always know what the video name will be.