[ Saturday, 28 July 2007, Treadstone ]
The program MOC was reviewed in recent article called MOC — Console Audio Player for Linux. It was written by Roman Tworkowski. Even though we live in the times of cute graphical interfaces e.g. Compiz, KDE, etc. I consider the MOC player to be a better solution for some users (including myself) than the very popular applications Xmms or Amarok, and the other visually appealing players. Why do I think so? Read on. I am about to describe some of the lesser known options of this excellent player.
My first argument for the MOC player is… the computer itself! I’m not going to deliver a lot of numbers to back up my statement, but some of you know very well what running a GUI based player like Amarok looks like on older or weaker machines. If the KDE environment wasn’t preloaded earlier, the graphical parts of Amarok alone force us to wait a long time before the player, with its libraries providing basic functionality, is loaded into the computer’s memory (so small in so many cases!).
The second argument for the player, perhaps the most salient one, is expressed best by this question: what are all those functions needed for? Let’s assume I’m a common man who wants to listen to music. I don’t need the music visualizations, the hundreds fancy skins, the fabulous image of my music player, the CD covers, or the advanced OSD (On Screen Display) modules. Really, the ability to listen to the music after logout is useful and appealing, you bet! Similarly, running the program from a console session might be beneficial if the X Window System went down “from an unknown cause”, especially after some new Linux tricks have been applied. And wouldn’t you like to play music during your system’s startup? Wouldn’t you like to control a player with a few commands, or make use of multimedia keys on your keyboards?
Are you swayed by these arguments? OK, let’s start then.
The installation process is easy, most distributions contain appropriate packages. I recommend you install moc-ffmpeg-plugin as well. You won’t be able to play wma, mp4, aac, and RealAudio files without this goodie. If distro makers do not provide the plugin you can download sources from the plugin’s official website.
Having gone through the installation process, the time for the first run has come. Type-in the mocp command in a console. A new window interface will pop up before your eyes. You can start playing music right away. To do this you have to find and mark music file in the player’s file manager (TAB will switch views) and press Enter. To stop playing press the “s” key, to pause press “p” or “space”. MOC makes intensive use of playlists. To add a new song to a playlist press “a”. If you want to add all song files from current directory press “a” and keep it pressed until all files are processed, or mark the directory and press “A”. Pressing “d” will delete a single item from a playlist; pressing “C” you’ll clear it all.
When your playlist is completed you’ll have to activate it using TAB. You’ll see the mark bar “jumping” to the playlist panel. Then press “l” (small letter l, like in llama ) – one of the two MOC panels will be closed leaving the MOC window with playlist contents. So use the TAB key to switch between the playlist view and the player’s view. A full list of the “key options” are shown at the end of the article.
I’ve attached an example config file below containing some comments. It is ready to use if you don’t want to fiddle with the configuration options – only the paths to directories should be changed.
- Download MOC Config File by Treadstone
If you configured the MOC player in different ways and you’d like to share the files with others, you are welcome to send them with short description to firstname.lastname@example.org.
Multimedia Keys in Keyboards – How to Use Them with MOC
Many modern keyboards are equipped with multimedia keys nowadays. They are sold with a set of drivers for Windows systems, why not make use of them under Linux (the keys not the drivers )? Luckily someone with the ability to do something about it had this idea and wrote the xbindkeys application which enables users to define all keyboard keys including multimedia ones. It should be available with most of the GNU/Linux distros. If not, its sources can be downloaded from author’s website and compiled according to provided method.
Having xbindkeys installed to hard disk you have to type in the following command in a console: xbindkeys -k. Then you should press the key you want to be bound to a command. You’ll see a message:
Press combination of keys or/and click under the window. You can use one of the two lines after "NoCommand" in $HOME/.xbindkeysrc to bind a key. "NoCommand" m:0x0 + c:160 NoSymbol
The last three rows must be copied to ~/.xbindkeysrc. NoCommand must be replaced with one of the following commands (inside quotation marks)
mocp --playto run MOC server and start playing,
or to play files if MOC server
that has been started earlier;
mocp --stopto stop playing;
mocp --toggle-pauseto pause on and off;
mocp --nextto play next song file;
mocp --previousto play previous song file;
You can type in other commands, see the MOC manual for more, but the above commands are the most important ones, I think.
More information on xbindkeys can be found with “man xbindkeys” or reading documentation from the official website.
MOC & System Monitor
Surely, some of you have wondered whether something could be done to have the playing song’s name shown on your computer’s Desktop, or whether it’d be possible to integrate MOC player with system monitor? I wouldn’t bother to say this if it wasn’t possible! How to do it? The player has a useful parameter “-info” which displays data about its activity. There’s the Conky program as well, which shows other programs’ output in its own window. So putting all the information together one could write a short script to fulfill his wishes. Here’s a script created by Folken:
#!/bin/sh TITLE="`mocp -i | grep 'Title:' | sed -e 's/^.*: //'`"; if [ "$TITLE" != "" ]; then ARTIST="`mocp -i | grep 'Artist:' | sed -e 's/^.*: //'`"; SONGTITLE="`mocp -i | grep 'SongTitle:' | sed -e 's/^.*: //'`"; ALBUM="`mocp -i | grep 'Album:' | sed -e 's/^.*: //'`"; if [ "$ARTIST" != "" ]; then ARTIST="$ARTIST - "; fi if [ "$ALBUM" != "" ]; then ALBUM="($ALBUM)"; fi echo $ARTIST $SONGTITLE $ALBUM else echo „MOC” fi
Simply stated, the script displays tags of the played file. If nothing is played the script writes a MOC message, where you can insert your own code, e.g. a message informing you the MOC is not running. Please keep in mind that MOC consists of two parts – a server and a client. To have the Conky showing its contents it’d suffice to add to its config file in an appropriate place:
If using Conky is out of question you can make use of a gkrellm plugin or gnome-panel applet. You can compile the additional programs but you have to have their sources. I didn’t test them as I do not use either gkrellm or gnome-panel but you can write to me if you come across problems with them. I’ll write an article then in which I’ll describe the plugins’ installation and configuration steps.
MOC and OSD
MOC (Music on Console) got no facility to show text on a screen in OSD mode – it is only a console based program. Until a user called robo, wrote on his Czech blog two Bash scripts using the osd_cat application. He wrote how to make the MOC player display the playing song’s title, artist’s name, album’s data, progress bar, and volume bar.
#!/bin/bash FONT=-adobe-helvetica-bold-*-*-*-24-*-*-*-*-*-*-* COLOR=red SHADOW=0 TOTALSEC=`mocp --info | egrep "TotalSec\:" | sed 's/TotalSec\:\ //'` CURRENTSEC=`mocp --info | egrep "CurrentSec\:" | \ sed 's/CurrentSec\:\ //'` PERCENT=`echo "$CURRENTSEC*100/$TOTALSEC" | bc` mocp --info | \ egrep "^Artist\:|^SongTitle\:|^Album\:" | \ osd_cat --offset=10 --indent=10 --color=$COLOR --font=$FONT \ --shadow=$SHADOW & osd_cat --offset=120 --indent=10 --color=$COLOR --font=$FONT \ --shadow=$SHADOW --barmode=percentage --percentage=$PERCENT
#!/bin/bash COLOR=red SHADOW=0 # pasek lub procenty BARMODE=slider VOLUME=`amixer get Master | grep Front.Left\: | \ sed -e s/" Front Left: Playback [0-9]* \["// | sed -e s/"\%.*"//` osd_cat --offset=10 --indent=10 --color=$COLOR --shadow=$SHADOW \ --barmode=$BARMODE --percentage=$VOLUME --delay=1
The first script shows song’s data. The second one shows current volume level – use it with the following commands:
amixer sset Master 1+-- to increase volume level or
amixer sset Master 1--- to decrease volume level
It’s a fairly good tool for volume control. You can do the same using xbindkeys like this:
"amixer sset Master 1+;~/.skrypty/volume.sh" alt + b:4 "amixer sset Master 1-;~/.skrypty/volume.sh" alt + b:5
These two entries in xbindkeys config file allow one to control volume level with the mouse wheel and the alt key. Moving the wheel up/down, and keeping left Alt button pressed, you’ll be able not only to change system volume but get feedback from a pretty progress bar, showing current volume level, as well. I invite those of you who have multimedia keyboards to investigate the above scripts.
MOC and Starting System
As I’ve mentioned, MOC can play files without running a character interface, and after the logout procedure. So why not add the MOC player to the startup scripts? That way the last system scripts could be run simultaneously with nice sounds played in a background. You only need to add to system services a script with mocp command. You’ll find short description how to do that in article about rTorrent.
I think you’ll find the above information useful and convincing. That consoles and applications or scripts written for them do not have to be any less useful than their GUI counterparts or difficult to get running. Perhaps also that they are the best remedies for some kind of problems new Linux users can run up against. And now, here’s the list of MOC option keys I promised to attach.
List of MOC Keys
enter -- starts playing s -- stops playing n -- plays next item from the playlist b -- plays previous item from the playlist space -- pause p -- pause S -- plays at random R -- repeats the same song in a loop, Next (X button below) must be OFF X -- switches to play sequentially o -- plays a file from the Internet u -- moves playlist item up j -- moves playlist item down Ctrl+u -- adds the URL to the playlist g -- searches marked string in file names / -- searches marked string in file names r -- rereads the directory T -- switches to the theme selection menu f -- toggles display mode of song titles TAB -- switches marker bar between the playlist and the file manager panels l -- switches between displaying the playlist or the file manager panel P -- switches full path in the playlist H -- toggles hidden files view Ctrl-t -- toggles song duration time Ctrl-f -- toggles format file view m -- moves to directory entered in config file G -- moves to directory with currently played file i -- moves to marked directory U -- moves to upper directory a -- adds a file to the playlist A -- adds a directory recursively to the playlist C -- clears the playlist V -- saves the playlist d -- removes marked item from the playlist Y -- removes all empty items from the playlist < -- decreases volume by 1% , -- decreases volume by 5% > -- increases volume by 1% . -- increases volume by 5% x -- toggles the mixer channel ? -- shows help ! -- goes to a fast dir 1 (set in config file) @ -- goes to a fast dir 2 # -- goes to a fast dir 3 $ -- goes to a fast dir 4 % -- goes to a fast dir 5 ^ -- goes to a fast dir 6 & -- goes to a fast dir 7 * -- goes to a fast dir 8 ( -- goes to a fast dir 9 ) -- goes to a fast dir 10 F1 -- executes ExecCommand1 (set in config file) F2 -- executes ExecCommand2 F3 -- executes ExecCommand3 F4 -- executes ExecCommand4 F5 -- executes ExecCommand5 F6 -- executes ExecCommand6 F7 -- executes ExecCommand7 F8 -- executes ExecCommand8 F9 -- executes ExecCommand9 F10 -- executes ExecCommand10
I’m expecting one kind of questions in the comments in particular – why not MPD, which offers similar if not better functionality. I dunno. I use the MOC player myself and I find it more friendly for fresh Linux users than others. Besides this article was aimed at the newbies, wasn’t it?
Proof-read by chaddy
Subscribe to RSS feed for this article!