LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2022, 08:49 AM   #1
OkanB
LQ Newbie
 
Registered: Oct 2022
Posts: 3
Blog Entries: 1

Rep: Reputation: 0
Loop Video on startup. Raspberry Pi OS.


Hello everyone,

I got the assignement to transform a Raspberry Pi into a Videolooper on Startup. The thing is, i have never worked with a Raspberry Pi at all. So my first thought was to install Raspberry Pi OS on it.
One main Problem is, that i cannot connect the rasp to the internet. So i was forced to only use the utilities given with the OS(vlc media is installed). And on top of that i saw this as a learning opportunity (so dont use OS image files ), so im basically trying to write a script to loop the presentation.
I was able to get to a point where Rasp plays the video on startup. I did that with a .desktop file. https://forums.raspberrypi.com/viewtopic.php?t=17051
Now the problem with the Method described in the post is that you have to have the Video file located at a specific spot on the rasp with a specific name.

But the looper has one main cirteria:
- the video is supposed to be located on a usb stick, with ideally no name
specifications

I have been trying to run everything through a bashscript but find myself limited by my minimal knowledge on Linux.

I got a hint to try using systemd services. That's a thing Im looking into.

Im not expecting anyone to give me a full script on how to create a videolooper. Id sum up my post in a couple of questions:

1. Does it make sense to use a Bashscript for this particular purpous.

2. If Bashscripts are the way to go, how do I retrieve a file from a usb-stick using a
Bashscript.

3. Does anyone have some good reasources to learn about systemd services or .desktop
or at the very least some nudges to the write direction?
 
Old 10-26-2022, 09:32 AM   #2
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Create the bash script to do what you need done.

Then create a systemd .service file in /usr/lib/systemd/system/ to run that bash script whenever the usb device is plugged in and mounted or use a .desktop file to run it whenever the user logs in.

The .service file can be used to run it at bootup or at mount time. A service is not dependent upon a user logged in, though the DE & DM must be fully operational for something like vlc to display on the screen. This usually requires a user to be logged in for the DE & DM to be active.

A .desktop file and the method used in that link can be used for running the script at login (or at boot if you configure the user for auto-login at boot time.) The user already logged in meets the requirement for the DE & DM to be active to support vlc display.

You can design the script to run as a daemon so it can be started at boot and will run in the background, sleeping, and wait for a usb device to be plugged in and execute when that occurs. This is essentially what a service does for many things.

In any case the script must be configured to verify the usb device is present before it can run vlc on the video files contained.

Setting anything up to run automatically means you must set certain conditions for the path to the files being used and those conditions must always be met or the app will fail. Scripting can use if-then or case tests and loops to select from a variety of options within the script itself while executing.

Hope this gives you some ideas on how to structure your app.

Last edited by computersavvy; 10-26-2022 at 09:37 AM.
 
1 members found this post helpful.
Old 10-26-2022, 05:09 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,740

Rep: Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923Reputation: 5923
Welcome to LinuxQuestions

If you can connect the Pi to the internet there is already software for a video looper. I assume by now it is built for the lastest version of Pi OS.

https://learn.adafruit.com/raspberry-pi-video-looper/
 
1 members found this post helpful.
Old 10-31-2022, 10:05 AM   #4
OkanB
LQ Newbie
 
Registered: Oct 2022
Posts: 3

Original Poster
Blog Entries: 1

Rep: Reputation: 0
Hello Guys.

First off all, thank you very much for your inputs. It's very much appreciated.
I have a few follow up questions though.

I cant use the downloading of other tools because i have no internet on the pi where i am at. So I'm trying to use the tools given from the start. Such as vlc media.
My current issue is that when I start vlc Media player the thread of my Bashscript stops. I wanted to make it so that when you start vlc media player the script continues in a loop where it waits for the user to unplugg the usb-stick.
When that happenes it returns into a loop where the pi waits for the user to insert the usb stick. But it never gets past the command where i launch vlc media player. So when i unplugg the usb stick it just continues playing the presentation.
How would i deal with that?

This is how my Bashscript looks like at the Moment:
------------------------------
#!/bin/bash

DIR="/media/pi"
DIR2="/home/pi/Videos"

if [ "$(ls -A $DIR2)" ]; then
sudo rm /home/pi/Videos/*.mp4
fi

while true
do

if [ "$(ls -A $DIR)" ]; then

FILE=$(find /media/pi -maxdepth 2 -name *.mp4)

cp $FILE /home/pi/Videos/movie.mp4
vlc /home/pi/Videos/movie.mp4 <- this is where the thread stops

while [ "$(ls -A $DIR)" ]
do
echo "usb is still plugged in"
sleep 30
done

pkill vlc

fi

done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Raspberry Pi: Combine a Raspberry Pi with up to 4 Raspberry Pi Zeros for less than US$50 with the Cluster HAT LXer Syndicated Linux News 0 07-05-2019 12:03 PM
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 03:50 AM
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 05:17 PM
while loop or for loop? mijohnst Programming 18 11-21-2005 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration