Saturday, December 27, 2014

Quick Android Ringtone

My son was making himself at home in his Android phone Christmas present yesterday. He wanted a particular guitar solo as his ringtone.  Here's how I put it together. Spoiler alert, it's much easier than this:

  1. Slice out the guitar solo using itunes
  2. Convert the MP3 to ogg
  3. Added the ANDROID_LOOP metadata
  4. Copied the ringtone to the phone

Slice out the guitar solo using itunes

You can configure iTunes to export songs in MP3. You can also tell iTunes to start/stop playing at certain points in a song.
  1. select the song you want to use
  2. CMD-I to open the settings dialog
  3. Go to the Options tag to enter your start/stop time. This will likely take some fiddling to get the slice you want. With these set, the song will only play this section.
  4. Now open the File menu -> Create New Version -> Create MP3 Version
  5. You probably want to go back to the CMD-I properties dialog to clear the start/stop time of this song

Convert the MP3 to ogg

A drag-n-drop later I had an ogg file out of the mp3 by using Media Human. This ogg will work as a ringtone. However there is a long pause before it loops. This is not what we wanted. 

Added the ANDROID_LOOP metadata

I found Audacity to add the loop metadata key/value pair. Drag-n-drop the ogg file into Audacity. Then File menu -> Export Audio. Choose your destination file location and press the Save button. Now you get a new dialog where you can enter the new metadata key/value pair: ANDROID_LOOP:true.

Copied the ringtone to the phone

Android File Transfer works slick. Drag-n-drop the file from a Finder window into the Ringtones directory of android file transfer.  You don't have to disconnect the USB cable, navigate on your phone to Settings->Sounds and pick your ringtone!


In the end I could have just used Audacity since my music library is already MP3 format. I did not have to get iTunes to export an AAC into MP3. Audacity will let you select a section of song by clicking and dragging. Then further adjust the start/stop points. Simple go to the same File menu -> Export Selected Audio.

Sunday, March 23, 2014

Scala Play Framework Template Imports

The template compiler is pretty sweet. Using a template like a function is awesomely simple.  If you have a bit of html code that makes up a reused block on more than one page you just factor it out to it's own ___.scala.html. Then reference it with the "magical" @ character.

However, the error messages that the template engine provides are less-than-detailed. I had created a subdirectory named: app/views/tags. When I tried to use one of the template functions out of that directory I got the error: not found: value gallery

So let's take a look at the important parts.

I have templates:

  • app/views/main.scala.html
  • app/views/tags/gallery.scala.html
With this as the important parts of main.scala.html

@(artist: models.ArtistModel,
      tags: List[String])(implicit artistModel: Option[models.ArtistModel]) @import tags._
Hmmmm, "not found: value gallery"? Why can't it find gallery? I imported it. It's formed correctly. Well, this is painfully obvious now, but it took a few minutes for me to reconcile that the "tags: List[String]" is clashing with the "@import tags._" 

More on the Play Framework Templates