Log in

No account? Create an account
On the geek beat - an albuquerque not animate be armada. — LiveJournal [entries|archive|friends|userinfo]
Okrzyki, przyjaciel!

[ website | My Website ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

On the geek beat [Oct. 12th, 2004|12:01 pm]
Okrzyki, przyjaciel!
If you install Red Hat Enterprise Linux, as my dept recently did, there's no applications to play mp3 files. Some time ago I made a build of MPlayer which will play some movie files in Firefox that didn't seem supported by RHEL out of the box.

mplayer has zero user interface -- well, you can run it in a shell window and it will interpret keys you type as transpfort controls, but that's a fairly antediluvian UI. But if you're a keyboard jockey, it ain't so bad.

The good thing, though, if you actually use a terminal window and shell commands, is that it's easy to tell mplayer to play a bunch of files:

mplayer *.mp3

Or to play all the files in the current directory and all its subdirectories:

mplayer ` find . -name \*mp3 `

To generate a random playlist, I needed a stream randomizer

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
int main(int argc, char **argv)
std::vector<std::string> lines;
std::copy(std::istream_iterator<std::string>(std::cin), std::istream_iterator<std::string>(), std::back_inserter (lines));
std::copy (lines.begin(), lines.end(), std::ostream_iterator<std::string> (std::cout, "\n"));

So now i can use mplayer to generate a random playlist of all the mp3 files in the current directory:

mplayer ` find . -name \*mp3 | randomize `

x09 has a programmer interview question to put interviewees on the spot. The brute force solution I give above uses the Standard Template Library to produce a very concise correct answer to this problem. Unfortunately, it depends on buffering up the whole file before shuffling the lines and writing them back out. Not so good when you feed it a 32-gigabyte list of numbers or something.

Tom's preferred solution only buffers two line of the input stream at a time. Every time you read a line, you either print it out, or, based on a random probability, you print out the saved line and save the current line.

This is the sort of thing my mind rebels against, but last week with clues from x09 I had a solution that unfortunately, I deleted. I tried to replicate it today to no avail, so I guess I don't get the job with him ;-) Maybe he'll favor us with his solution.

[User Picture]From: dooriya
2004-10-12 10:43 am (UTC)
i use xmms to play mp3's and mplayer for all the rest. red hat works, but sometimes i miss some of the comforts of windows.
(Reply) (Thread)