Synchronizing music with an Android device

| No Comments

Oh. Oh my.

I have a small music collection: about 8000 files, and growing steadily. I want to keep a copy of my collection on my Android phone. (I’ve been keeping a full copy of my collection on some portable device for fifteen years now, and I don’t see why I should stop now.)

My collection is too large to fit into my phone’s `internal storage’, which appears to be whatever change is left out of 32GB by the phone’s firmware. So I bought a 64GB µSD card to keep the music on.

I initially made the copy by physically plugging my µSD card into my laptop’s MMC slot, mounting it, and running rsync(1). rsync is awesome.

Then I bought a new CD. (These are silvery discs which store uncompressed digital audio.) As usual, I copied the audio data off the CD, encoded it as FLAC, tagged it using MusicBrainz Picard, entered into my master archive, and then invoked my audio conversion gremlin to make Ogg Vorbis for satellite devices. Now all I need to do is copy the new Ogg Vorbis files to the phone.

And that’s where the trouble started.

  • I run Termux on my phone, because life without a competent Unix shell isn’t worth living. So, I thought, I’ll just install rsync on the phone, and run that. Haha! Nope. Nowadays, even apps which have the WRITE_EXTERNAL_STORAGE permission aren’t actually allowed to write to where the µSD card is mounted (/storage/label) through the Unix filesystem API. rsync, of course, expects that to work, and ends up with a ‘permission denied’ error.

  • OK, next attempt: plug the phone into my laptop with a USB cable, and push the new files using rsync from the laptop. Android lost the ability to present its external storage as a USB mass-storage device, and the best available option is MTP. Only (Android’s implementation of) MTP is terrible. In particular, enumerating the files in a directory is really slow. Like, nearly a second per file. Did I mention 8000 files? That’s over two hours to do nothing.

  • I could take the SD card out of the phone and plug it back into the laptop. Trouble is, when I was setting the phone up, I managed to toast two of my old 64GB µSD cards taking them in and out, so I’m kind of reluctant to try this.

  • OK, so actually I have root on my phone. Attempt one: just run rsync as root. Then ssh complains that my ~/.ssh/config file is writable by the Termux user — which is true, but unimportant — and won’t play. Fiddling with $HOME doesn’t seem to help, so I don’t know how to fix this. I can’t run rsync as root.

  • Attempt two: as root, move the audio archive under Android/data/com.termux/files/, where Termux can mess with it, run rsync as a peon to update it, and move the whole lot back again as root. Only that doesn’t work, because it seems that the strange Fuse layer which is enforcing app separation on the external storage is keeping track of where the files came from and still refuses to play.

  • Attempt three: like the previous attempt, only this time, root moves the files around in /mnt/media_rw/label rather than in /storage/label, confusing the Fuse machinery. This actually seems to work. rsync will write to the audio tree. VLC will find the audio and play it. There’s probably some indexing thing I’ll have to tickle, but so far I’m good.

Why? Why does it have to be this hard?

Leave a comment