public final class Manager extends Object
Manager
is the access point for obtaining
system dependent resources such as Players
for multimedia processing.
A Player is an object used to control and render media that is specific to the content type of the data.
Manager
provides access to an implementation specific
mechanism for constructing Players
.
For convenience, Manager
also provides a simplified
method to generate simple tones.
The
playTone
function is defined to generate
tones. Given the note and duration, the function will
produce the specified tone.
Manager
provides three methods to create aPlayer
for playing back media:The
- Create from a media locator.
- Create from a
DataSource
.- Create from an
InputStream
.Player
returned can be used to control the presentation of the media.The simplest way to create a
Player
is from a locator in the URI syntax. Given a locator,createPlayer
will create aPlayer
suitable to handle the media identified by the locator.Users can also implement a custom
DataSource
to handle an application-defined protocol. The customDataSource
can be used to create aPlayer
by using thecreatePlayer
method.A third version of
createPlayer
creates aPlayer
from anInputStream
. This can be used to interface with other Java API's which useInputStreams
such as the java.io package. It should be noted thatInputStream
does not provide the necessary random seeking functionality. So aPlayer
created from anInputStream
may not support random seeking (alaPlayer.setMediaTime
).
AllPlayers
need aTimeBase
. Many use a system-wideTimeBase
, often based on a time-of-day clock.Manager
provides access to the systemTimeBase
throughgetSystemTimeBase
.
Content types identify the type of media data. They are defined to be the registered MIME types ( http://www.iana.org/assignments/media-types/); plus some user-defined types that generally follow the MIME syntax (RFC 2045, RFC 2046).For example, here are a few common content types:
- Wave audio files:
audio/x-wav
- AU audio files:
audio/basic
- MP3 audio files:
audio/mpeg
- MIDI files:
audio/midi
- Tone sequences:
audio/x-tone-seq
- MPEG video files:
video/mpeg
A data delivery protocol specifies how media data is delivered to the media processing systems. Some common protocols are: local file, disk I/O, HTTP, RTP streaming, live media capture etc.Media locators are used to identify the delivery protocol (as well as the identifier/name of the media).
Media locators are specified in URI syntax which is defined in the form:<scheme>:<scheme-specific-part>
The "scheme" part of the locator string identifies the name of the protocol being used to deliver the data.
Some media specific locator syntax are defined below:
1. Locators for Live-media Capture
The locators for capturing live media are defined by the following syntax in Augmented BNF notations:
"capture://" device [ "?" media_encodings ]To identify the type or the specific name of the device:
device = "audio" / "video" / "audio_video" / dev_name dev_name = alphanumeric alphanumeric = 1*( ALPHA / DIGIT )The syntax for specifying the media encodings are defined in Media Encoding Strings.
Examples:
capture://audio (default audio) capture://audio?encoding=pcm (default audio in PCM format) capture://devmic0?encoding=pcm&rate=11025&bits=16&channels=1 (audio from a specific device--devmic0)
capture://video (default video) capture://video?encoding=gray8&width=160&height=120 capture://devcam0?encoding=rgb888&width=160&height=120&fps=7
capture://mydev?myattr=123 (custom device with custom param)2. Locators for RTP streaming
RTP is a public standard for streaming media. The locator syntax for specifying RTP sessions is:"rtp://" address [ ":" port ] [ "/" type ]where:address and port defines the RTP session. The address and port usage is similar to the host and port usage as defined in the URI syntax.
type = "audio" / "video" / "text"
Example:
rtp://224.1.2.3:12344/audio3. Locators for Radio Tuner
To create aPlayer
to tune into a radio program, the following locator syntax is used:
"capture://radio" [ "?" tuner_params ]where:tuner_params = tuner_param *( "&" tuner_param ) tuner_param = "f=" freq / "mod=" modulation / "st=" stereo_mode / "id=" program_id / "preset=" preset freq = megahertz / kilohertz / hertz megahertz = pos_integer "M" / pos_integer "." pos_integer "M" kilohertz = pos_integer "k" / pos_integer "." pos_integer "k" hertz = pos_integer modulation = "fm" / "am" stereo_mode = "mono" / "stereo" / "auto" program_id = alpanumeric ; identifies an FM channel by its program service name (PS) delivered via Radio Data System (RDS)**. preset = pos_integer ; predefined tuning number** The RDS specification is available from http://bsonline.techindex.co.uk, id BSEN 50067:1998.
Examples:
capture://radio?f=91.9M&st=auto (91.9 MHz with automatic stereo setting) capture://radio?f=558k&mod=am (558 kHz with amplitude modulation) capture://radio?id=yleq (FM channel that has "yleq" as its program service name delivered via Radia Data System)
There are a few places where media encodings are specified as strings, e.g. in the capture media locator. Sections A to E define the encoding syntax. Section F defines the rules for how they should be handled.A. Describing media encodings:
media_encodings = audio_encodings / video_encodings / mixed_encodings / custom_encodingsB. Describing the audio encodings:
audio_encodings = audio_enc_param *( "&" audio_param ) audio_enc_param = "encoding=" audio_enc audio_enc = "pcm" / "ulaw" / "gsm" / content_type audio_param = "rate=" rate / "bits=" bits / "channels=" channels / "endian=" endian / "signed=" signed / "type=" audio_type rate = "96000" / "48000" / "44100" / "22050" / "16000" / "11025" / "8000" / other_rate other_rate = pos_integer bits = "8" / "16" / "24" / other_bits other_bits = pos_integer channels = pos_integer endian = "little" / "big" signed = "signed" / "unsigned" audio_type = bitrate_variable / other_type other_type = alphanumeric pos_integer = 1*DIGIT and content type is given in the MIME syntax.
Example:
encoding=pcm&rate=11025&bits=16&channels=1C. Describing the video or image encodings:
video_encodings = video_enc_param *( "&" video_param ) video_enc_param = "encoding=" video_enc video_enc = "gray8" / "rgb888" / "bgr888" / "rgb565" / "rgb555" / "yuv444" / "yuv422" / "yuv420" / "jpeg" / "png" / content_type video_param = "width=" width / "height=" height / "fps=" fps / "colors=" colors / "progressive=" progressive / "interlaced=" interlaced / "type=" video_type width = pos_integer height = pos_integer fps = pos_number quality = pos_integer colors = "p" colors_in_palette / = "rgb" r_bits g_bits b_bits / = "gray" gray_bits colors_in_palette = pos_integer r_bits = pos_integer g_bits = pos_integer b_bits = pos_integer gray_bits = pos_integer progressive = boolean video_type = jfif / exif / other_type other_type = alphanumeric interlaced = boolean pos_number = 1*DIGIT [ "." 1*DIGIT ] boolean = "true" / "false" and content type is given in the MIME syntax.
Examples:
encoding=gray8&width=160&height=120 encoding=jpeg&quality=80&progressive=true&type=jfif (progressive JPEG with quality 80 in jfif format) encoding=jpeg&type=exif (JPEG in exif format) encoding=png&colors=rgb888 (24 bits/pixel PNG) encoding=rgb888 (raw 24-bit rgb image) encoding=rgb&colors=rgb888 (raw 24-bit rgb image)D. Describing mixed audio and video encodings:
mixed_encodings = audio_encodings "&" video_encodings
Example:
encoding=pcm&encoding=gray8&width=160&height=160E. Describing custom media encodings:
custom_encodings = custom_enc_param *( "&" param ) custom_enc_param = "encoding=" value param = key "=" value key = alphanumeric value = alphanumericF. Rules for handling the encodings strings:
- If a given parameter is a custom parameter and is not recognizable by the implementation, the parameter is treated as an illegal parameter and the method must throw an appropriate Exception to denote that.
- If the value for a given parameter is incorrect because it is syntactically wrong or illegal (e.g. out of range), the method must throw an appropriate Exception to denote that.
javax.microedition.media.protocol.DataSource
,
Player
,
TimeBase
Modifier and Type | Field and Description |
---|---|
static String |
TONE_DEVICE_LOCATOR
The locator to create a tone
Player
to play back tone sequences. |
Modifier and Type | Method and Description |
---|---|
static Player |
createPlayer(InputStream stream,
String type)
Create a
Player to play back media from an
InputStream . |
static Player |
createPlayer(String locator)
Create a
Player from an input locator. |
static String[] |
getSupportedContentTypes(String protocol)
Return the list of supported content types for the given protocol.
|
static String[] |
getSupportedProtocols(String content_type)
Return the list of supported protocols given the content
type.
|
static void |
playTone(int note,
int duration,
int volume)
Play back a tone as specified by a note and its duration.
|
public static final String TONE_DEVICE_LOCATOR
Player
to play back tone sequences. For example,
try { Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR); p.realize(); ToneControl tc = (ToneControl)p.getControl("ToneControl"); tc.setSequence(mySequence); p.start(); } catch (IOException ioe) { } catch (MediaException me) {}If a tone sequence is not set on the tone
Player
via its ToneControl
,
the Player
does not carry any
sequence. getDuration
returns 0 for this
Player
.
The content type of the Player
created from this
locator is audio/x-tone-seq
.
A Player
for this locator may not be supported
for all implementations.
Value "device://tone" is assigned to TONE_DEVICE_LOCATOR
.
public static String[] getSupportedContentTypes(String protocol)
See content types for the syntax of the content types returned. See protocol name for the syntax of the protocol used.
For example, if the given protocol
is "http"
,
then the supported content types that can be played back
with the http
protocol will be returned.
If null
is passed in as the protocol
,
all the supported content types for this implementation
will be returned. The returned array must be non-empty.
If the given protocol
is an invalid or
unsupported protocol, then an empty array will be returned.
protocol
- The input protocol for the supported content types.public static String[] getSupportedProtocols(String content_type)
Player
's.
See protocol name for the syntax of the protocols returned. See content types for the syntax of the content type used.
For example, if the given content_type
is "audio/x-wav"
, then the supported protocols
that can be used to play back audio/x-wav
will be returned.
If null
is passed in as the
content_type
,
all the supported protocols for this implementation
will be returned. The returned array must be non-empty.
If the given content_type
is an invalid or
unsupported content type, then an empty array will be returned.
content_type
- The content type for the supported protocols.public static Player createPlayer(String locator) throws IOException, MediaException
Player
from an input locator.locator
- A locator string in URI syntax that describes
the media content.Player
.MediaException
- Thrown if a Player
cannot
be created for the given locator.IOException
- Thrown if there was a problem connecting
with the source pointed to by the locator
.public static Player createPlayer(InputStream stream, String type) throws IOException, MediaException
Player
to play back media from an
InputStream
.
The type
argument
specifies the content-type of the input media. If
null
is given, Manager
will
attempt to determine the type. However, since determining
the media type is non-trivial for some media types, it
may not be feasible in some cases. The
Manager
may throw a MediaException
to indicate that.
stream
- The InputStream
that delivers the
input media.type
- The ContentType
of the media.Player
.MediaException
- Thrown if a Player
cannot
be created for the given stream and type.IOException
- Thrown if there was a problem reading data
from the InputStream
.public static void playTone(int note, int duration, int volume) throws MediaException
SEMITONE_CONST = 17.31234049066755 = 1/(ln(2^(1/12))) note = ln(freq/8.176)*SEMITONE_CONST The musical note A = MIDI note 69 (0x45) = 440 Hz.This call is a non-blocking call. Notice that this method may utilize CPU resources significantly on devices that don't have hardware support for tone generation.
note
- Defines the tone of the note as specified by the
above formula.duration
- The duration of the tone in milli-seconds.
Duration must be positive.volume
- Audio volume range from 0 to 100. 100 represents
the maximum
volume at the current hardware level. Setting the volume to a
value less
than 0 will set the volume to 0. Setting the volume to greater than
100 will set the volume to 100.MediaException
- Thrown if the tone cannot be played
due to a device-related problem.Copyright (c) 1990, 2012, Oracle and/or its affiliates. All rights reserved.