|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--javax.microedition.media.protocol.DataSource
|
+--net.rim.device.api.media.protocol.ByteArrayInputStreamDataSource
A DataSource implementation that provides a seekable
SourceStream, given a ByteArrayInputStream.
A ByteArrayInputStreamDataSource can be passed into the Manager.createPlayer() method to create a seekable Player instance.
try {
ByteArrayInputStream stream = (ByteArrayInputStream)this.getClass().getResourceAsStream("/abc.mp3");
ByteArrayInputStreamDataSource source = new ByteArrayInputStreamDataSource(stream, "audio/mpeg");
Player p = Manager.createPlayer(source);
p.start();
} catch (IOException ioe) {
} catch (MediaException me) {
}
| Field Summary |
| Fields inherited from interface javax.microedition.media.protocol.SourceStream |
NOT_SEEKABLE, RANDOM_ACCESSIBLE, SEEKABLE_TO_START |
| Constructor Summary | ||
ByteArrayInputStreamDataSource(ByteArrayInputStream stream,
String type)
Creates a ByteArrayInputStreamDataSource. |
||
| Method Summary | ||
void |
connect()
Open a connection to the source described by the locator and initiate communication. |
|
void |
disconnect()
Close the connection to the source described by the locator and free resources used to maintain the connection. |
|
ContentDescriptor |
getContentDescriptor()
Get the current type for this stream. |
|
long |
getContentLength()
Get the size in bytes of the content on this stream. |
|
String |
getContentType()
Get a sting that describes the content-type of the media that the source is providing. |
|
Control |
getControl(String controlType)
Obtain the object that implements the specified Control interface. |
|
Control[] |
getControls()
Obtain the collection of Controls
from the object that implements this interface. |
|
int |
getSeekType()
Find out if the stream is seekable. |
|
SourceStream[] |
getStreams()
Get the collection of streams that this source manages. |
|
int |
getTransferSize()
Get the size of a "logical" chunk of media data from the source. |
|
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from the input stream into an
array of bytes. |
|
long |
seek(long where)
Seek to the specified point in the stream. |
|
void |
start()
Initiate data-transfer. |
|
void |
stop()
Stop the data-transfer. |
|
long |
tell()
Obtain the current position in the stream. |
|
| Methods inherited from class javax.microedition.media.protocol.DataSource |
getLocator |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ByteArrayInputStreamDataSource(ByteArrayInputStream stream, String type)
stream - A ByteArrayInputStream containing the entire contents of the media file to be played
by this DataSource implementation.type - The content type of the media.| Method Detail |
public void connect()
throws IOException
DataSourceconnect in class DataSource
DataSourceIOException - Thrown if there are IO problems when
connect is called.SecurityException - Thrown if the caller does not have security
permission to call connect.public void disconnect()
DataSource If no resources are in use, disconnect is ignored. If
stop hasn't already been called, callling
disconnect implies a stop.
disconnect in class DataSourcepublic ContentDescriptor getContentDescriptor()
SourceStream
SourceStreamContentDescriptor for this stream.public long getContentLength()
SourceStream
SourceStreampublic String getContentType()
DataSourcegetContentType in class DataSource
DataSourcenull if the content is unknown.IllegalStateException - Thrown if the source is not connected.public Control getControl(String controlType)
ControllableControl interface.
If the specified Control interface is not supported
then null is returned.
If the Controllable supports multiple objects that
implement the same specified Control interface, only
one of them will be returned. To obtain all the
Control's of that type, use the getControls
method and check the list for the requested type.
ControllablecontrolType - the class name of the Control.
The class name
should be given either as the fully-qualified name of the class;
or if the package of the class is not given, the package
javax.microedition.media.control is assumed.null.IllegalArgumentException - Thrown if controlType
is null.IllegalStateException - Thrown if getControl
is called in a wrong state.
See
Player
for more details.public Control[] getControls()
ControllableControls
from the object that implements this interface.
Since a single object can implement multiple
Control interfaces, it's necessary
to check each object against different Control
types. For example:
Controllable controllable;
:
Control cs[];
cs = controllable.getControls();
for (int i = 0; i < cs.length; i++) {
if (cs[i] instanceof ControlTypeA)
doSomethingA();
if (cs[i] instanceof ControlTypeB)
doSomethingB();
// etc.
}
The list of Control objects returned
will not contain any duplicates. And the list will not
change over time.
If no Control is supported, a zero length
array is returned.
ControllableControl objects.IllegalStateException - Thrown if getControls
is called in a wrong state.
See
Player
for more details.public int getSeekType()
SourceStreamNOT_SEEKABLE, SEEKABLE_TO_START and
RANDOM_ACCESSIBLE. If the return value is
SEEKABLE_TO_START, it means that the stream can only be
repositioned to the beginning of the stream. If the return value is
RANDOM_ACCESSIBLE, the stream can be seeked anywhere within
the stream.
SourceStreampublic SourceStream[] getStreams()
DataSourceDataSource provides the only indication of what streams may
be available on this connection.getStreams in class DataSource
DataSourceIllegalStateException - Thrown if the source is not connected.public int getTransferSize()
SourceStreamread method to read data from the
source.
SourceStreamSourceStream.read(byte[], int, int)
public int read(byte[] b,
int off,
int len)
throws IOException
SourceStreamlen bytes of data from the input stream into an
array of bytes. An attempt is made to read as many as len
bytes, but a smaller number may be read. The number of bytes actually
read is returned as an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
If b is null, a
NullPointerException is thrown.
If off is negative, or len is negative, or
off+len is greater than the length of the array
b, then an IndexOutOfBoundsException is thrown.
If len is zero, then no bytes are read and 0 is
returned; otherwise, there is an attempt to read at least one byte. If
no byte is available because the stream is at the end of the file, the
value -1 is returned; otherwise, at least one byte is read and stored
into b.
The first byte read is stored into element b[off], the
next one into b[off+1], and so on. The number of bytes read
is, at most, equal to len. Let k be
the number of bytes actually read; these bytes will be stored in elements
b[off] through b[off+k-1], leaving
elements b[off+k] through
b[off+len-1] unaffected.
If the first byte cannot be read for any reason other than end of
file, then an IOException is thrown. In particular, an
IOException is thrown if the input stream has been closed.
SourceStreamb - the buffer into which the data is read.off - the start offset in array b at which the data is
written.len - the maximum number of bytes to read.-1 if there is no more data because the end of the stream
has been reached.IOException - if an I/O error occurs.
public long seek(long where)
throws IOException
SourceStreamseek method
may, for a variety of reasons, fail to seek to the specified
position. For example, it may be asked to seek to a position beyond the
size of the stream; or the stream may only be seekable to the beginning
(getSeekType returns SEEKABLE_TO_START). The
return value indicates whether seeking is successful. If it is
successful, the value returned will be the same as the given
position. Otherwise, the return value will indicate what the new
position is.
If the given position is negative, seek will treat that as 0 and attempt to seek to 0.
An IOException will be thrown if an I/O error occurs, e.g. when the stream comes from a remote connection and the connection is broken.
SourceStreamwhere - The position to seek to.
public void start()
throws IOException
DataSourcestart method must be called
before data is available for reading.start in class DataSource
DataSourceIllegalStateException - Thrown if the DataSource is
not connected.IOException - Thrown if the DataSource cannot be
started due to some IO problems.SecurityException - Thrown if the caller does not have security
permission to call start.
public void stop()
throws IOException
DataSourceDataSource has not been
connected and started, stop is ignored.stop in class DataSource
DataSourceIOException - Thrown if the DataSource cannot be
stopped due to some IO problems.public long tell()
SourceStream
SourceStream
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2009 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.