Play songs at certain times


#1

Hello, can someone help me out. Im new to ubuntu and want to use a raspberrypi woth ubuntu mate to play songs during the day at a specific times. What software do u all recommend to do that?

Thanks!


#2

use vlc in command line mode in conjunction with crontab

I haven't got time this minute to write out a set of instructions. But, will do so later today for you


#3

Thanks Steve, i will really appreciate the commands to do it.


#4

Okay. So, the first thing required is to explain some stuff about VLC

VLC is a multimedia player that you are probably used to only running with a GUI. However, it will also run from a terminal command and, if you use the correct prefixes and suffixes to the VLC command you can get it to play in the background in "hidden" mode.

A basic VLC command to run a particular audio file might be:

vlc elvis-1-track1.wav

This would run the above file (a) if you happened to have a terminal opened at the same location as the file is stored and (b) it would open the VLC player GUI to actually play the file.

To play the file without the GUI, you would need to prefix the command "vlc" with "c". So, the command would now be:

cvlc elvis-1-track1.wav

This command would run vlc in hidden mode. But, again, it would only run the file if the terminal was opened at the location of the file. To open the above file from a location that is not the same as the location the terminal was opened at, you would need to include the full path to the file. For example:

cvlc /mnt/d72c6179-4d77-49f4-9ee3-5cf63f70d3ce/Audio/Elvis-Collection/Elvis1/elvis-1-track1.wav

This would play the file with vlc in hidden mode. However, there is a little quirk in vlc. This quirk is that VLC, run from a command line, will not actually exit following the playing of the file and so hangs around in memory after the file has finished playing. To remedy this, you need to add the suffix:

--play-and-exit

So, the command, in full, would be:

cvlc --play-and-exit /mnt/d72c6179-4d77-49f4-9ee3-5cf63f70d3ce/Audio/Elvis-Collection/Elvis1/elvis-1-track1.wav

The above command would play the file in vlc in hidden mode from any location whose path was fully stated and would exit after the file finished playing.

One final thing to note when using vlc in command line mode. All files and folders need to have no spaces. Generally speaking, I have found using terminal commands on files and folders with spaces in them tends to not work properly. So, wherever you have your audio files and folders stored, make sure the ones you intend to use this command on have no spaces or, if you want to keep words in the files/folders separate from one another, separate then with a dash (-). You may have already noticed me using this convention in my commands, above.

Okay, so that is it for now with vlc.

On, now, to Crontab.

Cron is an event scheduling program that comes pre installed in Debian and, I think, comes pre installed with Ubuntu as well. If not, you can easily install it with "sudo apt-get install cron".

Assuming it is installed, you would edit your cron setting via a file called crontab. To edit this, open a terminal and issue the following command:

crontab -e

This will open the crontab file. It may ask you which editor to use (nano or tiny). If so, choose "nano" editor. This editor runs inside the terminal. Once in the file, scroll to the bottom of the file. see below:

You will notice, at the bottom of the file, are the following letters (m) (h) (dom) (mon) (dow)

These stand for "minute", "hour", "date of month", "month", "day of week"

If you are intending to play your file every single day of every single week of every single month, then you only need to put in a value for the minute and hour. for each of the other values, you should enter an "*", This will tell crontab to accept any value for these fields.

So, the command to use in the crontab file to play my Elvis song every single day at a specific time could be:

40 22 * * * cvlc --play-and-exit /mnt/d72c6179-4d77-49f4-9ee3-5cf63f70d3ce/Audio/Elvis-Collection/Elvis1/elvis-1-track1.wav

This command would be entered as the last line in the crontab file. See below for an example:

This command would play my file at 10:40 pm every evening

To close the editor and save, you need to press "CTRL/x", press "y" to accept the changes and then press "Enter"


#5

Thank you so much for the information. I will try it out later tonight. Thanks once again​:+1::+1:


#6

keep checking the above post.. I am adding to it


#7

Are you wanting to play single files or a collection of files at a given point in time?


#8

Single .mp3 files each time.


#9

I have never used it, but think you may be able to stack up a collection of songs to be played in succession one after the other if you use the "&&" command inside your crontab command. So, for example:

50 22 * * * cvlc --play-and-exit /mnt/d72c6179-4d77-49f4-9ee3-5cf63f70d3ce/Audio/Elvis-Collection/Elvis1/elvis-1-track1.wav && cvlc --play-and-exit /mnt/d72c6179-4d77-49f4-9ee3-5cf63f70d3ce/Audio/Elvis-Collection/Elvis1/elvis1-track2.wav

I'm just testing that out now....


#10

yes, I can confirm that stacking up songs to be played in succession works


#11

Awesome! Now i know in case one day i need to stack up songs


#12

I finally had a chance to try ur commands today and it works flawlessly. Thanks again for ur help! :+1: