Yet Another Blog by Nitesh Mistry

Entries tagged "mpg123"

Light Music - Internet Radio with mpg123
31st December 2010

Light music? No, I am not talking about any genre of music but about being light on your system while playing music.

Recently, I started playing (with) internet radio - one of the perks of having a unlimited broadband internet connection. Playing internet radio within the browser means managing one more window which needs to stay open all the while (constantly using around 100 MB of system memory), even if I am not browsing the web. So the other alternative is to give the url to your favourite gui music player to play. I use amarok for managing and playing locally stored music. It has a brilliant user interface to browse my music, manage playlists and all. But any modern graphical audio player also has a big memory foot-print (considering my poor 6 year old box) - grabbing almost 50-70 MB of RAM. And, since while playing internet radio, songs are automatically queued by the station, there is very little for me to tinker around, and the audio player usually stays minimised in the system tray.

Then why waste so much of resources when there is mpg123 to do the task. And it does the task really well. It runs from the terminal and still provides basic functionality (read man mpg123 for details). While it is playing, just check your system monitor; mgp123 rarely uses more than 700 KB of system memory (that is just 1% of what graphical audio players occupy) and it never shows up in the top 10 CPU users. As someone wisely said, "Frugal living is a virtue".

Wow! So how to go about it? Simple, run the following at the terminal:

sudo apt-get update; sudo apt-get install mpg123

To play internet radio with mpg123:

mpg123 <url of the radio station> &

For example, mpg123 & will play the classical guitar channel at internet radio station.

To stop playing the music, just bring the process up giving fg command and interrupt it with ctrl-c or simply kill the process by giving killall mpg123 command.

Cool. Now enjoy the "light" music. ;)

Email comments to Nitesh Mistry   Tags: geekosophy, howto, internet, linux, mpg123, music, radio.
Computer as an Alarm Clock?
24th September 2010

We all like to wake up listening to good music instead of blaring noise of alarm clock or mobile phones. And, when it comes to sleep, if you are as much like Kumbhakarna as I am, chances are that you hit the snooze/stop button even without opening the eyes and sleep for another hour.

So I was always looking for a solution, where I could set my computer as an alarm clock, and play my favourite song or playlist to wake me up. This way I will have to get out of my bed and come to the desk to stop it, by which time I would have gained my senses. Similar question was also asked by someone in Mumbai Linux Users Group mailing list some time ago (I am not able to locate the exact thread right now).

But there was a two part problem in doing this:
One - I did not want to keep my computer switched on the whole night (you know how hip it is to be 'green' now-a-days); and
Two - How to play the songs without creating the security/privacy issue of making the computer log in to my user-space automatically.

But for linux users, no problem is too big to be solved.

First problem got solved when I came accross this great article by Mechatotoro. Until I read his post I was completely ignorant of a nifty feature residing in my computer's BIOS. To enter the BIOS settings, press DEL key (or depending on your computer make, F2 or F12 key) immediately after pressing the power button of the computer. On this white-and-blue screen, navigate to the Power Management Setup section. Now go to Resume by Alarm option and select Enabled. Set the day and time field immediately below that. Press F10 key and when prompted to save the settings press Y and Enter.

That is it and now the computer will automatically get powered on at the set day and time. Ofcourse I will need to keep the main power switch on, as I am using a desktop computer. No need to worry about this if you are using a laptop.

Now the second problem. One reason why I did not want to use Mechatotoro's solution as-it-is, was that, that involved setting up auto-login. How to play the songs without setting auto-login on the computer as it is a potential security and privacy hazard. Thankfully, most linux operating systems (including Ubuntu) have a nifty little feature named cron. Here all the users of the system can set up their own list of tasks to be executed automatically at the specified date and time. For example, fetching mails from the remote server every 5 minutes, or as in my case, play the specified song at a particular time of the day.

But using cron has a small little problem. While it can let any graphical audio players play the songs when the user is logged in, it cannot do so if the user is not logged in. In my case, since I would be asleep when the computer starts in the morning, I will not be able to feed in the password for my account to let cron play the songs. So I turned to my friends at Mumbai Linux Users Group for help and as expected, they pitch in right away. The problem it seemed was that, not all audio players can play songs without user being logged in. After many trials and errors, I was suggested to try mpg123, and it worked!

So here's how to put down the second problem:

Dan-te-naaaan! I am all set to wake up in the morning and do Pranayaam and Sudarshan Kriya. No more excuses.

Oh, but how do I stop the song?
Option 1 - Enter my password to log in to the computer > Fire up a terminal > type killall mpg123
Option 2 - Oh, I have a multimedia keyboard! So I just press the mute button.
Option 3 - Why should I stop it at all. Thats my favourite song, isn't it? I enjoy it while I brush my teeth and have morning cuppa.

So all you lazy bones, you have one less excuse to not get up in the morning.

Email comments to Nitesh Mistry   Tags: alarm, auto-power-on, bios, cron, geekosophy, howto, linux, mpg123.