Page 3
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW IN YOUR JURISDICTION, IN NO EVENT SHALL RIM BE LIABLE FOR ANY TYPE OF DAMAGES RELATED TO THIS DOCUMENTATION OR ITS USE, OR PERFORMANCE OR NON-PERFORMANCE OF ANY SOFTWARE, HARDWARE, SERVICE, OR ANY THIRD PARTY PRODUCTS AND SERVICES REFERENCED HEREIN INCLUDING WITHOUT LIMITATION ANY OF THE FOLLOWING DAMAGES: DIRECT, CONSEQUENTIAL, EXEMPLARY, INCIDENTAL, INDIRECT, SPECIAL, PUNITIVE, OR AGGRAVATED DAMAGES, DAMAGES FOR LOSS OF PROFITS OR REVENUES, FAILURE TO REALIZE ANY EXPECTED SAVINGS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, LOSS OF BUSINESS OPPORTUNITY, OR CORRUPTION OR LOSS OF DATA, FAILURES TO TRANSMIT...
Start the media application with or without content................10 Streaming data from a remote source to the media application ............11 Creating a BlackBerry Application that plays media files .................15 Change the state of a Player ........................17 Play media in a BlackBerry Application ....................17 Receive and send media application events ..................19...
Page 6
Detect when an image is added or removed in the file system............35 Retrieving an image from the file system ....................37 Retrieve an image from memory on a BlackBerry device..............37 Retrieve an image from a microSD card ....................37 Moving an image in the file system ......................
BlackBerry Applications and multimedia BlackBerry Applications and multimedia You can create a BlackBerry® Application that plays media in the BlackBerry® Browser, or plays media in the media application on the BlackBerry smartphone. You can also create a BlackBerry Application that is a media application.
Page 8
BlackBerry Java Development Environment Multimedia Development Guide...
Connector FileConnection You can create a BlackBerry® Application that uses the class and interface to access media stored on the BlackBerry smartphone or a microSD card. Access media on a BlackBerry smartphone > Invoke Connector.open() . Pass the following parameters: the file protocol and the location of the media file on the BlackBerry®...
BrowserSession soundclip = Browser.getDefaultSession(); 2. Invoke BrowserSession.displaypage() soundclip.displayPage("file:///SDCard/BlackBerry/Video/soccergame.avi"); Playing media in the media application On the BlackBerry® smartphones that include the media application, a BlackBerry Application can use the javax.microedition.content net.rim.device.api.content packages to start the media application with or without content.
2: Using audio and video in a BlackBerry Application Streaming data from a remote source to the media application To stream data from a remote source to the media application, you must buffer the source and control how the DataSource SourceStream media application reads the data.
Page 12
System.out.println("Initial Buffering Complete"); // Buffering is complete if (_stop) { return; //The entire file is now in the InputStream and in memory on the BlackBerry smartphone. System.out.println("Downloading Complete"); System.out.println("Total Read: " + totalRead); // If the size of the downloaded file does not match the size of the file reported by the server, print a message.
Page 13
2: Using audio and video in a BlackBerry Application DataSource Specify the following four parameters in the to define how an application buffers data: Item Description Initial buffer the amount of audio data that the application downloads before it starts to play the data Pause mark determines when the application’s attempts to read data from the buffer are blocked...
Page 14
BlackBerry Java Development Environment Multimedia Development Guide restart_pause = false; return _baseSharedStream.read(b, off, readLength); } else if (!restart_pause && (available > getPauseBytes() || available > readLength)) { //Determine if a previous read operation was paused and if there is enough data in the buffer to perform a read operation.
2: Using audio and video in a BlackBerry Application saveFile = (FileConnection) Connector.open("file:///SDCard/blackberry/music" + filename, Connector.READ_WRITE); //If a file with the same name as the remote file doesn't exist on the local system, download the file again. if (!saveFile.exists()) { saveFile.create();...
Page 16
BlackBerry Java Development Environment Multimedia Development Guide State Description Player PREFETCHED An instance of a class that implements the interface can perform tasks that are required to play media. Player STARTED An instance of a class that implements the interface can start playing media.
2: Using audio and video in a BlackBerry Application Change the state of a Player Task Step Change the state of a Player from UNREALIZED REALIZED Player.realize() Invoke Change the state of a Player from Player.prefetch() REALIZED PREFETCHED Invoke Change the state of a Player from Player.start()
Page 18
VideoControl 7. Implement the methods of the interface to give a BlackBerry® Java® Application a variety of video playback support features. Perform one of the following actions: • control the mode of video display through the use of USE_GUI_PRIMITIVE or USE_DIRECT_VIDEO •...
Close the media application. 1. Invoke Player.close() 2. Invoke Receive and send media application events To create a BlackBerry® Java® Application that listens for and sends media application events, you can use the API items in the javax.microedition.media (JSR 135) package. Task...
BlackBerry Java Development Environment Multimedia Development Guide Create different kinds of players javax.microedition.media To play audio on a BlackBerry® smartphone, you can use the API items in the (JSR 135) package. You must create a media application and then add functionality to it.
Page 21
VideoControl.initDisplayMode(int mode, Object arg) . Pass the following parameter: an arg value that specifies the UI primitive that displays the video. For example, in a BlackBerry® Application, use "net.rim.device.api.ui.Field" as the arg parameter, casting the object that this method Field returns as a object.
Page 22
BlackBerry Java Development Environment Multimedia Development Guide Code sample: Playing a sequence of tones // "Mary Had A Little Lamb" has "ABAC" structure // Use block to repeat "A" section byte tempo = 30; // 30 x 4 = tempo of 120 bpm byte duration = 8;...
Page 23
2: Using audio and video in a BlackBerry Application Code sample: Playing media from an input stream //First we determine the supported content types String types[] = Manager.getSupportedContentTypes(null); for (int cnt = types.length - 1; cnt >= 0; --cnt) { if (types[cnt].equals("audio/mpeg")) {...
BlackBerry Java Development Environment Multimedia Development Guide Record audio on a BlackBerry smartphone The BlackBerry® smartphone uses two formats to record audio: Adaptive Multi-Rate (AMR) and 8 kHz mono-16-bit pulse code modulation (PCM). By default, the format is AMR. Thread...
Page 25
2: Using audio and video in a BlackBerry Application 9. Configure the output stream to which the application records data. _rcontrol.setRecordStream(_output); 10. Start recording the audio and start playing the media from the Player. _rcontrol.startRecord(); _player.start(); 11. In a catch block, specify that a notification dialog displays with a message about an exception, if one occurs.
BlackBerry Java Development Environment Multimedia Development Guide private ByteArrayOutputStream _output; private byte _data[]; VoiceNotesRecorderThread() {} private int getSize() return (_output != null ? _output.size() : 0); private byte[] getVoiceNote() return _data; public void run() { try { // Create a Player that records live audio.
Page 27
2: Using audio and video in a BlackBerry Application Player Player.realize() 2. To allow a to get media resources, invoke p.realize(); Player.prefetch() 3. Invoke p.prefetch(); Player Player.getControls() 4. To get the controls that a supports, invoke Control[] c = player.getControls();...
Page 28
BlackBerry Java Development Environment Multimedia Development Guide...
MediaManager You can create a BlackBerry Application that uses methods from the class to access a .pme file stored on the BlackBerry smartphone or a network location. You can create a BlackBerry Application that uses the MediaPlayer methods from the class to play a .pme file.
} catch (MediaException me) { System.out.println("Error: requested content type is not supported.”); Allow a screen to display a The screen of the BlackBerry® Application must not support scrolling. .pme file that the Plazmic® > Create an instance of a screen object using the NO_VERTICAL_SCROLL and NO_HORIZONTAL_SCROLL Media Engine Version 4.2...
See “Code sample: Implementing a listener to download SVG content” on page 46 for more information. Task Steps MediaListener Listen for media engine 1. Implement the interface to let your BlackBerry® Application listen for media engine events. events. mediaEvent() 2. Implement to handle all possible media events.
2. In , add code to manage the event that occurs background, and play it. when the application finishes loading a .pme file to the BlackBerry® smartphone. MediaPlayer.setMedia(data 3. To register the content, invoke MediaPlayer.start() 4. To start playback, invoke manager.createMediaLater("http://webserver/sample.pme");...
Create a custom connection to SVG content You can create a BlackBerry® Application that can download SVG content from the Internet or from local storage MediaManager using a connection that supports a custom protocol or has functionality that the does not support or provide.
Page 34
BlackBerry Java Development Environment Multimedia Development Guide releaseConnection(ConnectionInfo) 4. To release the custom connection, implement releaseConnection(ConnectionInfo) 5. To register a custom connector, implement...
Creating an image with the camera Start the camera from a BlackBerry Application Invoke You can create an application that uses the class to start the camera so a BlackBerry device user can take a picture. > Invoke Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments()) Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());...
Page 36
11. Perform actions if a file was added or deleted from the file system. switch (entry.getEvent()) { case FileSystemJournalEntry.FILE_ADDED: //either a picture was taken or a or a picture was added to the BlackBerry device break; case FileSystemJournalEntry.FILE_DELETED: //a picture was removed from the BlackBerry device;...
Retrieve an image from memory on a BlackBerry device > Invoke Connector.open() with the file protocol and the location of the image on the BlackBerry device as parameters. FileConnection fconn = (FileConnection)Connector.open("file:///store/home/user/ pictures/newfile.jpg"); Retrieve an image from a microSD card >...
Deleting an image from the file system Delete an image from memory on a BlackBerry device Invoke Connector.open() with the file protocol and the location of the image on the BlackBerry device as parameters. FileConnection fconn = (FileConnection)Connector.open("file:///store/home/user/ pictures/newfile.jpg"); FileConnection.delete() 2.
4: Working with images from the camera Delete an image from a microSD card Connector.open() Invoke with the file protocol and the location of the image on the microSD card as parameters. FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/pictures/ newfile.jpg"); 2. Invoke FileConnection.delete() fconn.delete();...
Page 40
BlackBerry Java Development Environment Multimedia Development Guide...
> Invoke BlackBerry® smartphone supports a color screen. Graphics.getNumColors() Determine the number of > Invoke colors that the BlackBerry smartphone screen supports. Configure the pixel 1. Invoke one of the following methods: transparency in the drawing Graphics.setGlobalApha() • area. Graphics.getGlobalAlpha() •...
Page 42
BlackBerry Java Development Environment Multimedia Development Guide Task Steps Graphics.isRopSupported(int) Determine the raster 1. Invoke operations that the 2. Provide one of the following constants as a parameter: BlackBerry® Java® ROP_CONST_GLOBALALPHA • : blends the constant foreground color using a constant global alpha Application supports.
Steps Access an image. 1. Save the image to the project folder or subfolder. 2. Add the image to the project in the BlackBerry® Integrated Development Environment. Class.getResourceAsStream() 3. Invoke to retrieve the image as an input stream of bytes.
Page 44
• : decodes an alpha channel, if one exists (this is the default mode) DECODE_NATIVE • : forces the BlackBerry® Java® Application to decode the bitmap to the native bitmap type of the BlackBerry® Device Software DECODE_READONLY • : marks the decoded bitmap as read-only EncodedImage.setScale().
Code sample: Using an unprocessed image to recreate an encoded image Code sample: Drawing a new bitmap using an existing bitmap Code sample: Retrieving and displaying SVG content The MediaSample.java sample downloads a .pme file from a content server and displays it on the BlackBerry® smartphone. * MediaSample.java * Copyright (C) 2001-2007 Research In Motion Limited.
BlackBerry Java Development Environment Multimedia Development Guide try { Object media = manager.createMedia(“http://webserver/SVGFILE.pme”); player.setMedia(media); } catch (IOException ioe) { } catch (MediaException me) { System.out.println(“Error during media loading: “); System.out.println(me.getCode()); System.out.println(me.getMessage()); add((Field)player.getUI()); try { player.start(); } catch(MediaException me) { System.out.println(“Error occured during media playback: “);...
Page 47
6: Code samples public MediaSample2() { _screen = new MediaSample2Screen(); pushScreen(_screen); public final class MediaListenerImpl implements MediaListener { public void mediaEvent(Object sender, int event, int eventParam, Object data) { switch(event) { case MEDIA_REQUESTED: System.out.println(“Media requested”); break; case MEDIA_COMPLETE: System.out.println(“Media completed”); break;...
BlackBerry Java Development Environment Multimedia Development Guide Code sample: Using an unprocessed image to recreate an encoded image * ImageDemo.java * Copyright (C) 2001-2007 Research In Motion Limited. All rights reserved. package com.rim.samples.docs.imagedemo; import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*;...
6: Code samples try { EncodedImage image = EncodedImage.createEncodedImage(data, 0, data.length); add(new BitmapField(image.getBitmap())); } catch (IllegalArgumentException iae) { System.out.println(“Image format not recognized.”); Code sample: Drawing a new bitmap using an existing bitmap To draw a new bitmap image, the DrawDemo.java sample downloads unprocessed data from a predefined bitmap image.
Page 52
BlackBerry Java Development Environment Multimedia Development Guide Bitmap original = Bitmap.getPredefinedBitmap(Bitmap.INFORMATION); Bitmap restored = new Bitmap(original.getType(), original.getWidth(), original.getHeight()); Graphics graphics = new Graphics(restored); // Retrieve raw data from original image. int[] argb = new int[original.getWidth() * original.getHeight()]; original.getARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());...