I'm currently working on a custom audio player app for an online music
site. It has the following main requirements:

a) I need to be able to play music without waiting for it to download.

b) I wish to cache the music locally so that the user's favourite tracks
don't need to be downloaded again.

Currently my strategy is to download the files locally and discard the
oldest ones when I need more space, keeping all the metadata in an
associated SQLite database; but this approach is rather problematic and
very brittle due to having to keep the database and the files in sync,
issues with ensuring that a file isn't removed when something else is
wanting to use it, etc. Not the least of which is that caching entire
files means using up rather a lot of disk space --- some of my music
files can be 15MB+.

Also, MediaPlayer appears to be very picky as to what it plays from: it
insists on playing from a file, or at least a file descriptor, and when
you start playing it measures the length of the file and won't play past
the end point, which is a bit of a problem if you haven't finished
writing it yet. At least 0.9 has fixed the issue where getDuration()
used to calculate the duration of the media based on the physical file
length.

Can anyone suggest any alternative approaches to doing this? What I'd
*really* like to do is to be able to store my entire cache in a single
huge fixed-size file, optionally on the SD card, and stream fragments
directly to MediaPlayer; but I don't think that's possible and Java
would probably be too slow anyway. Alternatively, a block-level cacheing
HTTP proxy would do almost as well. Does Android have one?

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ "All power corrupts, but we need electricity." --- Diana Wynne Jones,
│ _Archer's Goon_

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to