Home > Articles > Web Services > XML

  • Print
  • + Share This
Like this article? We recommend

Creating a List of Ring Tones

The extended RTTTLPlayer application, RTTTLEx, will show a list of five ring tones (tunes) on the cell phone screen. The user will then be allowed to select from this list.

Before I start programming, I need to solve a problem. How do I make it so that when a user selects a tune, say "TheFifth," the application knows to play the associated RTTTL file? I solve this problem by abstracting the tune into two parts: the caption of the ring tone, and the URL with which the caption is associated. I do this by creating two arrays (see Listing 1):

  • mcaptions will hold the captions

  • murls will hold the URLs

Listing 1 Creating the mcaptions and murls String Arrays

//Make the URL for the ring tones constant
private static String website = "http://www.CogArtTech.com/tones/";

//Create an array of captions
private String[]  mcaptions = {"TheFifth","Octaves","Scales","Bach","LottaLove"};

/*Create an array of URLs where the elements will be
associated with the captions array*/
private String[]  murls = {website + "fifth.rtl", website +
"octave.rtl", website + "minscale.rtl", website + 
"dmInvent.rtl", website + "love.rtl"};

Eventually I will pass both of these arrays to a class that renders the tune's captions on the cell phone's screen and plays the contents of the tune's URL—in this case, an RTTTL string—on the cell phone. Because the offsets of both arrays, mcaptions and murls, are identical, each caption is implicitly associated to a corresponding URL. The first element in mcaptions ("TheFifth") is the caption of the tune; the first element in murls ("fifth.rtl") is the URL of that tune. The second element of mcaptions ("Octaves") is the caption of the second tune, matching the second element of murls ("octave.rtl"), and so forth.

NOTE

Notice that I isolate the base URL for the web site where the ring tones reside (my web site, www.CogArtTech.com) into the variable named website. I do this to make the code more compact and maintainable.

Once I have these two arrays made, it's time to assign the captions for the ring tones to an MIDP List component for display on the cell phone screen and make it so that the user can play a selected ring tone.

  • + Share This
  • 🔖 Save To Your Account