Troubleshooting guide

58
BlackBerry Java Development Environment Development Guide
Code sample: Managing rich media content download events
Example: Managing rich media content download events
public void mediaEvent(Object sender, int event, int eventParam, Object data) {
switch(event) {
...
case MEDIA_IO: {
LoadingStatus s = (LoadingStatus)data;
}
Register the listener. >Invoke addMediaListener() on the MediaPlayer and MediaManager objects.
private MediaListenerImpl _listener = new MediaListenerImpl();
private MediaPlayer player = new MediaPlayer();
private MediaManager manager = new MediaManager();
player.addMediaListener(_listener);
manager.addMediaListener(_listener);
Load the content in the
background, and play it when
the download is complete.
1. To download the content for future playback, invoke MediaManager.createMediaLater().
2. In MediaListener.mediaEvent(), add code to manage the MEDIA_REALIZED event that occurs
when the content that the application downloads finishes loading on the BlackBerry® device.
3. To register the content that the data parameter specifies, invoke MediaPlayer.setMedia(data).
4. To start the playback, invoke MediaPlayer.start().
manager.createMediaLater("http://webserver/sample.pme");
public void mediaEvent(Object sender, int event, int eventParam, Object data) {
switch(event) {
...
case MEDIA_REALIZED:
try {
player.setMedia(data);
player.start();
} catch(MediaException me) {
System.out.println("Error playing media” + me.getCode() +
me.getMessage());
}
break;
}
}
Track the progress of a
download.
1. Extend the net.rim.plazmic.mediaengine.io.LoadingStatus class.
2. In your implementation of mediaEvent(), when the MEDIA_IO event occurs, cast the Object in the
data parameter to a LoadingStatus object.
3. To retrieve the download status and manage each status, invoke LoadingStatus.getStatus().
4. For each normal status, print a message to the console.
Manage a failed download. For the LOADING_FAILED status, perform the following actions:
1. To retrieve the error code, invoke LoadingStatus.getCode().
2. To retrieve the detailed message, invoke LoadingStatus.getMessage().
3. To retrieve the URL string of the content, invoke LoadingStatus.getSource().
Task Steps