Music

One would hope that playing/managing music on an Android device would be easy, but it’s broken. Here’s why…

I have a lovely HTC One (M8). For those that don’t know, it has forward facing speakers and can play music really loud. I’ve found that it’s now the main way that I listen to music. It also features a micro SD card. When I got it I copied my music collection to the card so I could listen to anything anywhere. But then I started to discover failings; artificial barriers put in place by Amazon and Google.

Amazon

I usually buy my music from Amazon. With my previous phone I didn’t much care where it stored the music. It only had internal phone storage. With this phone I want to keep all of my music together on the SD Card. Well, you can’t to that. The Amazon app will only store music to the phone memory. It’s also stored in protected folders, so moving it isn’t an option.

You can though download the music on you laptop and then move it to the SD Card. Amazon used to limit downloads to track at a time on the (Linux) desktop. They seem to have recently increased this to 24 tracks at a time, but that didn’t seem to work. Must recently I found that I had to download each track to the Downloads folder then create folders/move files in my Music folder. Good work Amazon!

(A warning about the Amazon MP3 Android app; it chews up loads of mobile data even if you don’t use it. Last month it was around 50Mb, which pushed me over my monthly allowance. I’ve disabled the app now.)

Google Play Music

So yesterday I thought I’d try buying music from Google’s Play Music store. I’d noted that the Play app does allow you to set the SD card as the storage device. However, much to my annoyance I found that it’s not stored in the Music folder. It’s stashed away in a folder that Google’s app can access but others can’t. Not only that, the tracks are stored in a flat folder with numeric names. Thanks Google, that’s pretty mean spirited of you.

Now, I could just use the Play Music app to play my music but it niggles me. It insists on opening to the Instant Mix screen and, I imagine, it probably reports everything that I listen to back to Google. (I don’t mind sharing data with Google, but even I have limits.)

As with music purchased from Amazon, I can download the music from Google to my laptop. This does work quite well under Linux, there’s a program that does a proper job of downloading to my Music folder.

So I’ve now downloaded recent purchases to my laptop and copied them to the micro SD card. I’ve also deleted the Amazon downloads from the internal phone storage and deleted the Google downloads from the secret “Google only” folder. The result is that I can now use HTC’s music player for everything.

 

 

Android Preferences
(and Library Projects)

I’ve been battling with preferences in Android, on and off, since November 2013.

I wrote an app, Pit Board, and at the time split the preferences into two dialog boxes. A simple one for the message text and colour and an more complex one for animation styles and timings. I just created these in dialogs and thought nothing of it.

The animation styles I stored the style as an integer and the animation speed as a long value. I can then use ‘switch’ for the animation style and directly use the long value for the animation. Android preferences allow the storage of these types of variable.

With further development/reading I then wanted to replace my dialog box with a standard PreferenceFragment, which should reduce the work that I do as it automatically stores the values. A change listener can then be used in the activity.

BUT! The standard preference classes don’t have anything for an integer backed list or a way to store long values. Not only that, when setting default values in XML there is no support for long values. As a result I have had to write classes to handle those, and the long values one is a kludge as it stores the defaults as integers.

Library Projects

Obviously, having taken the time to write these I want to be able to share them across apps. At first I tried to put them in a different package (a parent to those that I was for my apps) but this causes problems when compiling. Lots of errors about not finding resources (the R class).

Reading more it seems that projects can be defined as libraries and these can be incorporated at compile time. I set about moving the preferences (and another useful class) to “utils” this morning on the train. Poor internet access can be very frustrating! I studied the examples in the TicTacToe app, but got nowhere. When I tried to compile the project it failed to find the classes that I’d moved to the utility library.

I worked on it on the way home and made the same amount of progress. Once home I googled further and found a useful post which held the secret line that fixed it!

I’d already updated the project, but I hadn’t included the “--library relative/path/to/library/project” bit. When I look at the files I can’t just see what it altered, but it compiles now. (I’d already added the library reference to project.properties and even fixed the capitalisation!)

Handy Layouts

When developing Android applications the interface layout is usually defined in XML files. Commonly the file main.xml is the definition for the first interface that the application presents to the user.

Android also allows for different layouts to be defined in XML files in different folders. The names of the folders define when the layout should be used. So, for instance, the layout-land folder holds the layouts for the application when running on a device in landscape mode. This method allows design and function to be neatly separated.

It occurred to me on the train this evening, whilst working on an app, that it might be handy to have folders for left and right handedness. This would allow for asymmetric designs, especially in portrait mode, where the device – typically a phone – is being held in one hand. So if an application has multiple buttons on the display for instance, then the more important buttons could be sized/positioned to make them easier to reach.

I don’t know if this already exists, but I wanted to get it out there so that there is prior art, hopefully preventing the likes of Apple, Microsoft and RIM from claiming it as a novel invention and patenting it.

Android Timer Fault

Android Jelly Bean suffers a weird problem when setting a timer that is not on a ten minute interval.

I first noticed it when setting a timer for frozen pizza. They take 12 minutes, but I found that the alarm didn’t sound until much later. With some experimentation it seems that asking for a timer to be set over 10 minutes, but not at a ten minute interval, breaks things. It adds 90 minutes to the time.

Timer fault on Android
Illustration of Android timer fault

In this example I said “set a timer for 12 minutes”. As you can see from the time in the top right corner it was just after 10pm. The timer should have been set for 10.14pm but has been set for 11.44pm. If a request is made to “set a timer for 20 minutes” it seems to work.

I see this fault on both my phone (HTC One S running 4.1.1) and my Nexus 7 (4.2.2).

This issue seems to be fixed by recent updates.