Playing a sound file

by havoc

Is there really no Linux API to just play a file?

Something like:

id = cache_file("foo.ogg"); // cache the sample
play(id); // play to default device

libcanberra seems to only support playing stuff from a sound theme, not a file. PulseAudio seems to require setting up a main loop thing, creating a context, converting the file to a stream object in the right format, uploading the sample, and then finally playing it.

This should be a two-liner (with caching) and a one-liner without!

Which API should I know about?

(Is there at least an example of doing it with PulseAudio that can be quickly copied?)

My Twitter account is @havocp.
Interested in becoming a better software developer? Sign up for my email list and I'll let you know when I write something new.