Developers
Local Navigation
Mark Sohm, Research In Motion
An application has to provide the richest experience possible, using available tools, for a user to temporarily put aside reality and become lost in the experience. By simultaneously stimulating multiple senses, you can provide them with a feeling of being involved in the situation, instead of merely watching it from a distance.
Conversely, you might simply want users to think: "This is just plain cool!"
Topics within this section include:
- Multi-sensory user experience
- Beyond the visual experience
- Adding Vibration and Sound
- Using Plazmic Content In Your BlackBerry Application
Multi-sensory user experience
The BlackBerry wireless device is designed to deliver a multi-sensory user experience. The most obvious and commonly used method is to deliver visual content via the screen. BlackBerry has the ability to draw directly to the screen, allowing for custom animation. It also supports content created in the Plazmic Content Developers Kit (CDK), which can provide an interactive or animated experience that can include sound effects.
For more information on the Plazmic CDK, see the article, "Let me introduce you to ...", published in Volume 1, Issue 2 of the BlackBerry Developer Journal.
Beyond the visual experience
What if you want to go beyond just a visual experience, creating something that stands out from the crowd, because it's different and uses something that people are not used to? How about adding sound and motion to your application? This can be done on the device by making use of the Alert class:
net.rim.device.api.system.Alert
The Alert class will allow you to make use of audio and vibration alerts on the device. These can be used to notify a user of an event taking place in an application, or by having the device vibrate when the enemy space ship is destroyed in a game.
Adding Vibration and Sound
BlackBerry allows you to go beyond the visual experience with your application or game. With the use of the Alert class (net.rim.device.api.system.Alert), audio and vibration alerts can easily be added to your application.
The vibration alert will vibrate the device for the specified number of milliseconds, up to a maximum of 25,500. The vibration can also be stopped programmatically; cutting short the duration specified if another action is taken.
//Vibrate for 75 milliseconds. Alert.startVibrate(75);
Creating a sound alert involves two steps.
First, an array of shorts must be created. This will be passed to the audio alert method along with an integer that represents the volume level that ranges from 1 (softest) to 100 (loudest). This array defines the nature of the sound that will be played. The array is made up of pairs of values that represent the frequency and duration of a sound. The first value represents the frequency of the note that will be played and the second value represents its duration. Building the array to contain multiple pairs allows you to create a custom tune for your application. For example:
short[] explodeAudio =
{
300, 50, 500, 50, 300, 50, 500, 50, 300, 50
);
The second step is to play the sound:
Alert.playBuzzer(explodeAudio, 100);
Alerts can also be stopped at any point in time. This can allow you to play a long alert and then interrupt it when a certain action takes place. The stop methods are called to stop vibration or audio alerts.
//Stop Audio Alert Alert.stopAudio(); //Stop Vibrate Alert Alert.stopVibrate();
Using Plazmic content in your BlackBerry application
The Plazmic CDK can be used to create flashy and fun content. The first step in displaying Plazmic content is to instantiate the MediaPlayer and MediaManager. Once that is complete, an Object can be specified that contains the media field.
MediaPlayer mediaPlayer = new MediaPlayer(); MediaManager mediaManager = new MediaManager(); Object mediaFile;
Now we are ready to open the Plazmic content. Plazmic content can be referenced from a .cod file or a URL from the Internet. The following code shows an example of opening a PME file from within a .cod file.
try
{
mediaFile = mediaManager.createMedia("cod://MultimediaAlert/TankWars.pme");
mediaPlayer.setMedia(mediaFile);
//To reference a URL specify
// mediaFile = mediaManager.createMedia("http://yourserver/yourfile.pmb");
}
catch (Exception ex)
{
//Handle exception.
}
The Plazmic file is now open and can be added to the screen. Plazmic content is added to a screen in a fashion similar to a Field and supports similar properties. The animation process must be started if the Plazmic content contains animation.
Checking to ensure that the Plazmic content has been realized (or loaded) before starting the animation process ensures that a MediaException will not be thrown.
Object uiObject = mediaPlayer.getUI();
//Add the Object to the MainScreen.
mainScreen.add((Field)uiObject);
//If the MediaPlayers state is REALIZED,
//the media is loaded. Start the animation.
if (mediaPlayer.getState() == MediaPlayer.REALIZED)
{
try
{
mediaPlayer.start();
} catch (Exception e){
System.out.println(e.toString());
}
}
By making use of Plazmic content as well as the Alert class to add sound and vibration, you are able to enhance the user's experience and deliver that "wow" factor.
Please email your comments, suggestions and editorial submissions to mail