MOC Audio Player — advanced tricks
[ 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.
Installation
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.
Quick Start
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.
Configuration File
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 michuk@polishlinux.org.
Add-Ons
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:
${exec 30
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
and
#!/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 oramixer 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
Why MOC?
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
Warning: include_once(/sites/polishlinux.org/wp-content/themes/jakilinuxorg/google_article_inside.php): failed to open stream: No such file or directory in /sites/polishlinux.org/wp-content/themes/jakilinuxorg/single.php on line 48
Warning: include_once(): Failed opening '/sites/polishlinux.org/wp-content/themes/jakilinuxorg/google_article_inside.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /sites/polishlinux.org/wp-content/themes/jakilinuxorg/single.php on line 48
Subscribe to RSS feed for this article!
12 Comments
- A hyperlink: <a href="polishlinux.org">GNU/Linux for everyone!</a>,
- Strong text: <strong>Strong text</strong>,
- Italic text: <em>italic text</em>,
- Strike: <strike>
strike</strike>, - Code: <code>
printf("hello world");</code>, - Block quote: <blockquote>Block quote</blockquote>













If you like MOC, you should give mp3blaster a try. It is the best console-based music player I’ve seen. I’m still an Amarok guy, because I do like a lot of Amarok’s functions, and can’t live without it’s ability to handle a large library (17,000 songs). But when I just want to play a few songs, I fire up mp3blaster.
Excellent article – will download and install today.
I am a great believer in the utility and power of the command line – I still use mplayer in command line mode for everything.
Thanks again,
CD ‘Bar’ Baric
Excelent article, indeed
I’m not gonna use moc, but i do use mpd all the time, which is pretty much the same thing, with some database capabilities.
I highly recomend this tutorial for everyone
Moc is better than mpd in my opinion since, mpd keeps on running all the time draining the processor even when it is not required.
i used to use mpd but switched to moc b. it more fits my needs, i’m not playing remotely and moc can play files straight from my hd which mpd cant.
@ Ravi S. Ghosh
While your argument is valid, I don’t think MPD is that heavy on resources, not even noticeable.
@ tash
I use MPD to play files straight from my HD. MPD can play both locally and remotely.
I personally like MPD a lot, but I’m not completely satisfied by the MPD clients. I only wish MOC had support for MPD.
Wonderful article. I use both Moc and Mpd. Even though Moc is my primary music player, My roomy loves Mpd + Sonata. I share my computer with her so it’s kind of give and take. Both are very cool music players!
For some time I’ve been trying to get a conky execibar to display a songs length correctly. I don’t know much about scripting, but I can sure botch up a script a perectly good script with some fiddling! How would you add that fuction to your script above?
Good article, moc is my first music player option since three years. Thanks from Spain. Greets.
Great article, mocp is just what I didn’t know I was missing. Your scripts for conky are great too, though it’s faster to just call mocp -i once:
#!/bin/sh
mocp -i > mocpinfo
STATE=”`cat /home/user/.moc/mocpinfo | grep ‘State:’ | sed -e ‘s/^.*: //’`”;
TITLE=”`cat /home/user/.moc/mocpinfo | grep -m 1 ‘Title:’ | sed -e ‘s/^.*: //’`”;
if [ "$STATE" = "STOP" ]; then echo „MOC”;
elif [ "$TITLE" = "" ]; then
FILE=”`cat /home/user/mocpinfo | grep ‘File:’ | sed -e ‘s/^.*: //’`”;
echo ” $FILE “;
else echo ” $TITLE “;
fi
The speedup isn’t amazing unles (like I) you are also making a bar and paused/stopped indicator out of the same data. Those two scripts became three times as fast. As an added bonus it makes top look much neater!
Being a new Linux-convert myself, I find this tutorial really helpful..just installed MOC in my PC and now enjoying this simple yet efficient program. I hope you continue writing tutorials/how-tos to help those like me who have just made the move to Linux..more power to you!!!
Hello i am kavin, its my first occasion to commenting anywhere, when i read this piece of
writing i thought i could also make comment due to this brilliant
article.
This post presents clear idea designed for the new viewers of blogging, that truly how to do blogging.