Suppose you, a run of the mill Linux user, just downloaded a very long mp3 – for example a 10 hour mp3 of Cory Doctorow reading The Hacker Crackdown. Naturally you’re not going listen to this in one sitting; but, you cannot find a media player that implements bookmarking. What do you do?
You remember that hitting ^C (control-C) while mpg123 is playing a file will cause it to output something like
[56:36] Decoding of sterling_podcast.mp3 finished.
and then quit. What’s more, the -k option to mpg123 takes an integer n and starts playing the file it was passed n frames in. (For those of you unfamiliar with the structure of mp3 files, they store the audio data in segmented frames containing 26ms of audio data.) A quick invocation of Google tells you that 1 second of playback takes about 38.461 frames. So if you had a way to store mpg123’s output, you could use “mpg123 -k n /path/to/file” as a commandline mp3 player with rudimentary bookmarking.
But how do you store the output?
One of the great things about the commandline environment is its ability to pass output data around. One of the important elements of this flexibility is the “Standard Output,” which I’ll refer to stdout. For the uninitiated, stdout is where all the commandline programs send their output; usually, (and this is crucial) but not always, this is simply your terminal screen. However, it is possible to redirect this output to a file using (in Bash at least) the construct &>. An example:
The command “ls /home &> contents.txt” will write a list of the contents of the /home to the file contents.txt.
So there’s the answer. You can use
“mpg123 -k n /path/to/file &> .bookmark”
to play your long file, hit ^C to stop at any point, and be secure in the knowledge that you’ve got a bookmark waiting there for next time. If you wanted to be really fancy you could even write a simple script to pull the stopping point out of .bookmark and, after computing what n should be, launch mpg123.