Playing tones and tone sequences

To play a simple tone once, use:

Manager.playTone(note, duration, volume);

Playing tone sequences

To play a tone sequence, you must use ToneControl. Create a Player using a special locator, get the ToneControl, set its command sequence, and then start the player:

Player player = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR);
player.realize();
ToneControl tc = (ToneControl)(player.getControl("ToneControl"));
tc.setSequence(new byte[] { ToneControl.VERSION, 1,
                            ToneControl.C4, 8
                            ToneControl.C4 + 2, 8 });  // D4
player.start();

Note that you must call player.realize() before getting the tone control. You cannot get any type of control from a player before you have realized it.

ToneControl has byte commands for playing notes, creating and playing repeatable blocks of notes, and changing tempo, volume, and so on (see the Mobile Media API specificationMobile Media API specification for details).

None of the example code fragments presented in this section includes the necessary try/catch blocks for the various exceptions which can be thrown by the method calls.

A player for tone sequence from .JTS file (as well as other media file types) can be also created using protocols (http://, file://, https://).

Playing tones from stream

Tones can be played from stream in the same way as sampled audio and MIDIs.

First create InputStream to tone data and pass that stream to the Player

InputStream is = getClass().getResourceAsStream("/ukkonooa.jts");
Player player = Manager.createPlayer(is, "audio/x-tone-seq");

Once the player is created, you can add a listener, and then realize and prefetch the Player:

player.addPlayerListener(this);
player.realize();
player.prefetch();

Start the player when the tone should be played:

player.start();