Audio Player
The audio player is an API introduced so that audio can be played on the BlackBerry 5.0 operating system since the
HTML5 <audio> element is not yet supported on this OS. The audio player is intended to play audio files only
which does not include streaming audio.
It is recommended that you use the HTML5 <audio> element on BlackBerry Operating Systems with versions higher than OS 5.0 as well as on the Tablet OS.
The audio Player object is an instance object; if a new instance is desired, it must be created using the new keyword.
Supported Platform(s)
- BlackBerry OS 5.0+
- Ripple Emulator
API | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple |
---|---|---|---|---|---|
blackberry.audio.Player | Y | Y | Y | Y | |
addPlayerListener | Y | Y | Y | Y | |
close | Y | Y | Y | Y | |
pause | Y | Y | Y | Y | |
play | Y | Y | Y | Y | |
EVENT_BUFFERING_STARTED | Y | Y | Y | Y | |
EVENT_BUFFERING_STOPPED | Y | Y | Y | Y | |
EVENT_CLOSED | Y | Y | Y | Y | |
EVENT_DEVICE_AVAILABLE | Y | Y | Y | Y | |
EVENT_DEVICE_UNAVAILABLE | Y | Y | Y | Y | |
EVENT_DURATION_UPDATED | Y | Y | Y | Y | |
EVENT_END_OF_MEDIA | Y | Y | Y | Y | |
EVENT_ERROR | Y | Y | Y | Y | |
EVENT_RECORD_ERROR | Y | Y | Y | Y | |
EVENT_RECORD_STARTED | Y | Y | Y | Y | |
EVENT_RECORD_STOPPED | Y | Y | Y | Y | |
EVENT_SIZE_CHANGED | Y | Y | Y | Y | |
EVENT_STARTED | Y | Y | Y | Y | |
EVENT_STOPPED | Y | Y | Y | Y | |
EVENT_STOPPED_AT_TIME | Y | Y | Y | Y | |
EVENT_VOLUME_CHANGED | Y | Y | Y | Y | |
duration | Y | Y | Y | Y | |
mediaTime | Y | Y | Y | Y | |
state | Y | Y | Y | Y | |
volumeLevel | Y | Y | Y | Y | |
TIME_UNKNOWN | Y | Y | Y | Y | |
CLOSED | Y | Y | Y | Y | |
UNREALIZED | Y | Y | Y | Y | |
REALIZED | Y | Y | Y | Y | |
PREFETCHED | Y | Y | Y | Y |
Configuration Document Settings
To use all of the API described for this object, you must ensure the following settings are in your configuration document:
You must declare the feature element(s) below in your configuration document:
Feature ID | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple |
---|---|---|---|---|---|
<feature id="blackberry.audio.Player" /> | Y | Y | Y | Y |
Permission Elements (PlayBook Only) |
---|
This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application. |
API Summary
Constructors
Functions
Properties
- EVENT_BUFFERING_STARTED
- EVENT_BUFFERING_STOPPED
- EVENT_CLOSED
- EVENT_DEVICE_AVAILABLE
- EVENT_DEVICE_UNAVAILABLE
- EVENT_DURATION_UPDATED
- EVENT_END_OF_MEDIA
- EVENT_ERROR
- EVENT_RECORD_ERROR
- EVENT_RECORD_STARTED
- EVENT_RECORD_STOPPED
- EVENT_SIZE_CHANGED
- EVENT_STARTED
- EVENT_STOPPED
- EVENT_STOPPED_AT_TIME
- EVENT_VOLUME_CHANGED
- duration
- mediaTime
- state
- volumeLevel
Constants
blackberry.audio.Player
blackberry.audio.Player (locator : String, [type: String], [async: Boolean]) |
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Media locators are specified in URI syntax which is defined in the form: '<scheme>:<scheme-specific-part>'. If scheme is 'local', media type should be specified.
Parameter | Type | Description |
---|---|---|
locator | String | Media locator string in URI syntax that describes the media content. |
type |
String
Optional |
The ContentType of the media. |
async |
Boolean
Optional |
The parameter specifying whether the player should asynchronously advance to PREFETCHED state. If not provided set to false. |
Code Example(s)
<script type="text/javascript"> function createPlayerFromMediaFileStoredInLocal() { var playerInstance = new blackberry.audio.Player("local:///res/filename.mid", "audio/mid", true); } function createPlayerFromMediaFileStoresInSystem() { var playerInstance = new blackberry.audio.Player("file:///store/home/user/music/filename.mid"); } </script>
<script type="text/javascript"> // Display some player static and non-static constants. var playerInstance = new blackberry.audio.Player("file:///store/home/user/music/filename.mid"); var res = blackberry.audio.Player.UNREALIZED; alert("The value of UNREALIZED static constant is: " + res); res = playerInstance.EVENT_DURATION_UPDATED; alert("The value of EVENT_DURATION_UPDATED non-static constant is: " + res); </script>
<script type="text/javascript"> var playerInstance = new blackberry.audio.Player("file:///store/home/user/music/filename.mp3"); // Setting new time for media playerInstance.mediaTime = 10000; alert("New media time: " + playerInstance.mediaTime); // Setting new volume for media playerInstance.volumeLevel = 85; alert("New volume level: " + playerInstance.volumeLevel); </script>
addPlayerListener
static Boolean addPlayerListener([onPlayerUpdate: function]) |
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Add a player listener for this player. All subsequent calls assigning a new onPlayerUpdate callback will override the previous callback assigned. To unsubscribe from the PlayerListener, pass null as an onPlayerUpdate parameter.
Returns
Returns true if the callback is successfully assignedParameter | Type | Description |
---|---|---|
onPlayerUpdate |
function([player: blackberry.audio.Player], [event: String], [eventData: Object])
Optional |
This callback function is called to deliver an event to a registered listener when a Player event is observed.
player: The player which generated the event. event: The event generated as defined by the enumerated types. eventData: The associated event data. |
Code Example(s)
<script type="text/javascript"> // Subscribing and unsubscribing with player's events var playerInstance = new blackberry.audio.Player("file:///store/home/user/music/filename.mp3"); playerInstance.addPlayerListener(OnPlayerUpdate); // Invoked when there is an update event for the player. function OnPlayerUpdate(player, event, eventData) { try { alert("Player's duration is: " + player.duration) } catch (e) {} try { alert("Event: " + event); } catch (e) {} try { alert("Event Data: " + eventData); } catch (e) {} playerInstance.addPlayerListener(null); } </script>
close
static Boolean close() |
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Closing the Player and releases most of its resources, it must not be used again.
Returns
Returns true if the player is successfully closedpause
static Boolean pause() |
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Pause the player's playback.
Returns
Returns true if the player is successfully pausedCode Example(s)
<script type="text/javascript"> // Pausing the player and then closing it var playerInstance = new blackberry.audio.Player("file:///store/home/user/music/filename.mp3"); playerInstance.pause(); playerInstance.close(); </script>
play
static Boolean play() |
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Starts playing the loaded content.
Returns
Returns true if the player successfully starts playingCode Example(s)
<script type="text/javascript"> // Playing the player var playerInstance = new blackberry.audio.Player("file:///store/home/user/music/filename.mp3"); playerInstance.play(); </script>
Properties:
Property | Type | Description | Supported Platform(s) |
---|---|---|---|
EVENT_BUFFERING_STARTED |
Static String readonly |
Posted when the Player enters into a buffering mode. When this event is received, the eventdata parameter will be a number designating the media time when the buffering is started. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_BUFFERING_STOPPED |
Static String readonly |
Posted when the Player leaves the buffering mode. When this even is received, the eventData parameter will be a number designating the media time when the buffering stopped. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_CLOSED |
Static String readonly |
Posted when a Player is closed. When this event is received, the eventData parameter is null. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_DEVICE_AVAILABLE |
Static String readonly |
Posted when the system or another higher priority application has released an exclusive device which is now available to the Player. The eventData parameter is a string specifying the name of the device. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_DEVICE_UNAVAILABLE |
Static String readonly |
Posted when the system or another higher priority application has temporarily taken control of an exclusive device which was previously available to the Player. The eventData parameter is a string specifying the name of the device. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_DURATION_UPDATED |
Static String readonly |
Posted when the duration of a Player is updated. When this event is received, the eventData parameter will be a number designating the duration of the media. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_END_OF_MEDIA |
Static String readonly |
Posted when a Player has reached the end of the media. When this event is received, the eventData parameter will be a number designating the media time when the player reached end of media and stopped. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_ERROR |
Static String readonly |
Posted when an error had occurred. When this event is received, the eventData parameter will be a string object specifying the error message. Error code:
|
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_RECORD_ERROR |
Static String readonly |
Posted when an error occurs during the recording. When this event is received, the eventData parameter will be a string object specifying the error message. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_RECORD_STARTED |
Static String readonly |
Posted when recording is started. When this event is received, the eventData parameter will be a number designating the media time when the recording is started. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_RECORD_STOPPED |
Static String readonly |
Posted when recording is stopped. When this event is received, the eventData parameter will be a number designating the media time when the recording stopped. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_SIZE_CHANGED |
Static String readonly |
Posted when the size of the video is changed either because the source video size or the display size is changed. When this event is received, the eventdata parameter will be null. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_STARTED |
Static String readonly |
Posted when a Player is started. When this event is received, the eventData parameter will be a number designating the media time when the player is started. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_STOPPED |
Static String readonly |
Posted when a Player stops in response to the stop method call. When this event is received, the eventData parameter will be a number designating the media time when the player stopped. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_STOPPED_AT_TIME |
Static String readonly |
Posted when a Player is stopped as responding to the setStopTime call using the StopTimeControl. When this event is received, the eventData parameter will be a number designating the media time when the player is stopped. |
- BlackBerry OS 5.0+
- Ripple Emulator |
EVENT_VOLUME_CHANGED |
Static String readonly |
Posted when the volume of an audio device is changed. When this event is received, the eventData parameter will be null. |
- BlackBerry OS 5.0+
- Ripple Emulator |
duration |
Static Number readonly |
The duration of the media in milliseconds.
|
- BlackBerry OS 5.0+
- Ripple Emulator |
mediaTime |
Static Number |
Get/Set Player's media time.
|
- BlackBerry OS 5.0+
- Ripple Emulator |
state |
Static Number readonly |
The current state of this Player (one of Enumerated Player's constants).
|
- BlackBerry OS 5.0+
- Ripple Emulator |
volumeLevel |
Static Number |
Get/Set the player's volume level. Valid values are between 0 and 100.
|
- BlackBerry OS 5.0+
- Ripple Emulator |
Constants:
Property | Type | Description | Supported Platform(s) |
---|---|---|---|
TIME_UNKNOWN default: -1 | Number |
The returned value indicating that the requested time is unknown.
|
- BlackBerry OS 5.0+
- Ripple Emulator |
CLOSED default: 0 | Number |
The state of the Player indicating that the Player is closed.
|
- BlackBerry OS 5.0+
- Ripple Emulator |
UNREALIZED default: 100 | Number |
The state of the Player indicating that it has not acquired the required information and resources to function.
|
- BlackBerry OS 5.0+
- Ripple Emulator |
REALIZED default: 200 | Number |
The state of the Player indicating that it has acquired the required information but not the resources to function.
|
- BlackBerry OS 5.0+
- Ripple Emulator |
PREFETCHED default: 300 | Number |
The state of the Player indicating that it has acquired all the resources to begin playing.
|
- BlackBerry OS 5.0+
- Ripple Emulator |