Home > Articles > Web Services > XML

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

Playing a Tune

The work of playing the tune is delegated to an object called RTTTLPlayerLite. The sole purpose of RTTTLPlayerLite is to play RTTTL files. I adapted this object from work that I did in the ring tones article. When the RTTTLExCanvas object wants to play a tune, it passes the tune's URL to the playRTTTL() method of the RTTTLPlayerLite object (see Listing 9).

Listing 9 Creating a Ring Tone Converter To Play RTTTTL Ring Tones

public void playRTTTL(String url, Display display){
    display = display;
     try {
     //Create a player to play the RTTTL file
    tonePlayer =
       Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
    tonePlayer.realize();
    ToneControl tc =
     (ToneControl)tonePlayer.getControl("ToneControl");
    //Make a converter to make RTTTL file understandable
    //to the player
    RingToneConverter rtc;
     rtc = new RingToneConverter(url, "RTTTL Player");
    //Set the RTTTL file to the player
    tc.setSequence(rtc.getSequence());
    //Play it
    tonePlayer.start();
    }catch (Exception e) {
    //Create an error display, just in case.
    Alert alrt = new Alert(e.toString());
    alrt.setTimeout(Alert.FOREVER);
     display.setCurrent(alrt);
    }
}

This method contains the nuts and bolts necessary to play an RTTTL file downloaded from another location on the Internet. The mechanics of converting and playing ring tones are encapsulated in the RingToneConverter and ToneControl classes, which ship with the WTK. Thus, you can leverage the power of the WTK framework to play the selected ring tone without having to go through the difficult task of creating ring-tone conversion and playing code. As I said earlier, you can get a whole lot of power from the WTK without having to write a lot of code.

  • + Share This
  • 🔖 Save To Your Account