Execute terminal commands at startup on a Raspberry Pi
Execute terminal commands at startup on a Raspberry Pi
I'm working with a Raspberry Pi B running the latest Raspbian. I want to play several MP3 files in sequence automatically when the system starts up. Right now, using omxplayer and typing the file path directly doesn't work as expected. I need a solution so that upon startup (via local.rt or similar), the player starts one track, then another, and so on in a random order, looping after the last one finishes. I'm not very comfortable with shell commands or Linux, so I hope this helps. Thanks!
To ensure it functions properly, provide the person responsible for creating such code a location with the necessary files. Mention the media player you intended to use and clarify the context. I’ll note that setting MPlayer to play a random folder should also be viable. Having everything in one folder with this configuration will simplify setup. I’m familiar with the process. EDIT: OMXPlayer also works. EDIT: Further reading suggests Python might be a good option... EDIT: Additional notes are being reviewed.
I've conducted some investigation and discovered something useful. When you have files without spaces, disable the quotes on echo $line and try that setup—it works perfectly. Problems arise with spaces; using quotes or double quotes makes it interpret the path incorrectly, leading to errors like multiple files when one exists. Still, progress is being made. Script code for bash file sort.txt
So far, I've been working wtih omxplayer, but I don't care as long as it works. Actually, omxplayer doesn't have volume controls, so other things could be better. The path is /home/pi/Desktop/fourthofjuly.mp3 for one of them, all the others are just home/pi/Desktop/[nameofsong].mp3 I could put them in one folder, if I did that it would be /home/pi/Desktop/music/[nameofsong].mp3 Also, if I need to download anything, give me a link not meant to be taken straight on to the pi; my pi mysteriously won't connect to the internet.
They are all in one folder. Yes. It only needs basic Linux tools, which I can confirm. The updated file hasn’t been debugged again since I don’t have an Omniverse player, and I made a change to something that was working before. It should work fine. Here’s a bash script for sort.txt:
Sure, I can provide a script you can run in a shell or Python environment. Let me know if you need it tailored for Stack Overflow.