BlackBerry_Java_SDK-Development_Guide--1249411-0803110230-001-6.0-US

Page 5

Playing audio

Development Guide

}

3.

}

pushScreen(new AudioPlaybackDemoScreen());

Create the framework for the custom screen by extending the MainScreen class. class AudioPlaybackDemoScreen extends MainScreen { public AudioPlaybackDemoScreen() { } }

4.

In the screen constructor, in a try/catch block, create an instance of the Player class by invoking Manager.createPlayer(String), and passing in the location of the audio file to play. try {

Player p = javax.microedition.media.Manager.createPlayer("http://abc .com/sounds/abc.wav");

} catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); }

5.

To control an aspect of playback, retrieve the appropriate Control object. Invoke the Player object's realize() method to access its associated Control object. The following code sample demonstrates how to retrieve the VolumeControl object and set the volume level of playback. try {

Player p = javax.microedition.media.Manager.createPlayer("http://abc .com/sounds/abc.wav"); p.realize(); VolumeControl volume = (VolumeControl) p.getControl("VolumeControl"); volume.setLevel(30);

} catch(MediaException me) { Dialog.alert(me.toString()); } catch(IOException ioe) { Dialog.alert(ioe.toString()); }

3


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.