I need to run a script to play a video when I turn on my Raspberry Pi 4. I'm using crontab to run my script which opens a video with mpv. When I run the script normally, it works fine and the video is being played. The problem is, when i boot the raspberry, the script automatically runs but mpv doesn't .
here is my script:
#!/bin/bash
VIDEOPATH="/home/pi/Desktop/my-movie.mkv"
SERVICE="mpv"
while true; do
echo "playing "+$VIDEOPATH
$SERVICE --fs --start=00:00:00 $VIDEOPATH
done
I added this line to crontab:
@reboot /home/pi/Desktop/my-script.sh
I'm totally stuck in this. Any help saves my life!
The most practical solution I found to run GUI programs on startup is using Autostart. I created a .desktop file at /etc/xdg/autostart directory:
when
display
would be a custom name for my script. I added following lines the display.desktop :Saved the file and reboot the Pi.
As soon as my Pi boots up, my GUI program automatically start as well.