Android Development Details I
I’ve decided that from now on, along with all my Musical updates, I’m going to post some useful advice/tips/code/etc to help others solve any problems I might have encountered during the development of the update. So, here is the first of hopefully many “Android Development Details”
Today’s One Liner:
Get the current “android:versionCode” from AndroidManifest.xml:
getPackageManager().getPackageInfo(getPackageName(), 0).versionCode
Problem/Solution:
Once a media file has been detected on the SD card by Android’s MediaScanner, it is automatically to the MediaStore. The MediaStore is a SQL database used by all media-based applications instead of directly accessing the file system. Unfortunately, once an item has been added to the MediaStore, it is not immediately automatically removed when you delete the original file off the file system. This has to manually be done in the database. The easiest way I could find to do this is to get access to the Content Provider with getContentResolver() and call the delete() method with the arguments MediaStore.Audio.Media.EXTERNAL_CONTENT_URI (external because it is on the SD card) and a SQL WHERE clause indicating which file to remove. In my case, I needed the WHERE clause to find a specific file based on its path on the file system (since I had just deleted the original based on its path). The unix absolute path is stored in the MediaStore.Audio.Media.DATA (Note: this is a constant not a String–it must be concatenated into the SQL WHERE clause) column in the MediaStore database.
Hopefully these tips are helpful to some other Android developers, and as always, feel free to email me with any questions!
I like your musical application a lot. A couple of thoughts. A lot of keyboard players like the lower octave to be lower in a stacked keyboard arrangement. So, an option to switch the upper and lower octaves might attract more users/buyers. Second and MUCH more important would be to shorten the input/output latency. I don’t know where the problem lies but I do know that a fix for windows audio drivers called asio4all is very successful (Couldn’t find a linux version for you to look at). Finally, some recording option to save musical thoughts would be nice.
thanks for your efforts.
r
That should be pretty easy to allow switching the octaves, which I will try to do after the next release. There is no way for me to modify how Android’s audio works, so unfortunately until Google fixes it, there is nothing I can do about the latency. I am already using an unsupported and undocumented API to get the sounds to play at the current speed, because the “official” method is even slower. Hopefully this will be remedied in Cupcake (whenever that happens… April maybe?)
The feature you mentioned is now supported in the Piano Settings panel in Musical Pro (along with the choice of instrument and octaves)