So for a project that I am working on within the company I needed a solution that would allow a Raspberry Pi to automatically play a given video. I had issues with earlier versions and other hardware mainly Windows to get this to work very stable. Now I am a Windows man and using Linux is not much a second nature as I would like it to be but given the lightweight nature of Linux and the cost of Raspberry Pi’s it was worth a shot.
The first test we did was at least at the time I thought the most simple one was install VLC and call it a day. But strange things happened when using VLC. The video started lagging the same behavior which I noticed on the Windows hardware machines. As most people I am of course a fan of VLC but this left me a bit disappointed. Of course this could be due to software settings but the goal was to not over complicate if it was not needed.
So I checked online for some solutions and found out that Raspbian which I am running on the Raspberry Pi’s contained OMXPlayer. Now I didn’t know of this player before until the research I did but it worked amazingly well. OMXPlayer seems to use the hardware that is available to it’s advantage. I let it run for a day just to see if any stuttering or lagging would occur but it ran great.
With the player chosen it was time for the final setup. The goal was to make it so that anyone could use it and it’s only goal was playing that video so I did some very simple configuration tweaks to the standard Raspbian image that allowed me to do just that.
The first tweak was going into the ‘Panel Settings’ by right-clicking the taskbar above. Then I clicked on the ‘Advanced’ tab and checked the ‘Minimize panel when not in use’ option. Follow this up with changing the amount of Pixels to show from ‘2’ to ‘0’. This make it so that the taskbar above only appears if your mouse is around it.
Then I placed the video file I wanted to play in ‘/home/pi/Videos/VideoNameHere.mp4’. And set out to create the final and most important step to the system the autostart entry. This allows us to run a program when the Raspberry Pi is fully booted.
First check if there is a ‘autostart’ directory at ‘/home/pi/.config/’ using the terminal if not make it using ‘mkdir autostart’ which will make the directory for you. Then go into the directory you just made and from here we want to create a new file.
I personally like to use Nano as the editor but feel free to use whatever you want. In my case I used ‘nano autoomx.desktop’ to imply that this is an autostart script and starting the OMXPlayer. But this name is variable to whatever you prefer. You could go the ‘nano autoVideoNameHere.desktop’ route for example.
Now when in your favorite editor fill the script with the following lines changes it where needed to fit your needs
[Desktop Entry] Type=Application Exec=x-terminal-emulator -e omxplayer --loop /home/pi/Videos/VideoNameHere.mp4 --no-osd
Let us break this down. Why do I first start a terminal emulator and then use that to start OMXPlayer? Great question because otherwise you are likely to not be able to close it using the ‘Q’ key. So you could be stuck in a endless loop with no possible escape (I speak from experience). Then I tell OMXPlayer to loop a given video which I and you probably have placed in the Videos directory in your Home. Lastly I added the no osd switch. This removes any on screen text that displays. For example when it restarts the video it will Seek to the start and showing text we don’t want that.
Now close and save up your file and reboot and see the magic happen. Remember you can quit out of the player by pressing ‘Q’ if you need to make tweaks to suit your needs but for me this worked just fine.