DirectTonepublic final class DirectTone extends DirectPlayer implements ToneControlJava Tone Sequence Player
it implements ToneControl |
Constructors Summary |
---|
public DirectTone()It does not need data source
hasDataSource = false;
|
Methods Summary |
---|
protected Control | doGetControl(java.lang.String type)The worker method to actually obtain the control.
Control c = super.doGetControl(type);
if (c != null) return c;
if (getState() >= REALIZED) {
if (type.equals("javax.microedition.media.control.ToneControl")) {
return this;
}
}
return null;
| protected void | doRealize()the worker method to realize the player
// Get current isolate ID to support MVM
int isolateId = MIDletSuiteUtils.getIsolateId();
// Init native library
if (this.source == null) {
hNative = nInit(isolateId, pID, Manager.TONE_DEVICE_LOCATOR, Manager.TONE_DEVICE_LOCATOR, -1);
} else {
hNative = nInit(isolateId, pID, DefaultConfiguration.MIME_AUDIO_TONE, source.getLocator(), -1);
}
if (hNative == 0) {
throw new MediaException("Unable to realize tone player");
}
// if no source stream, player is created from TONE_DEVICE_LOCATOR
// simply return it.
if (stream == null) {
return;
}
// read the whole sequence from the source stream
int chunksize = 128;
byte[] tmpseqs = new byte[chunksize];
byte[] seqs = null;
// make use of BAOS, since it takes care of growing buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream(chunksize);
try {
int read;
while ((read = stream.read(tmpseqs, 0, chunksize)) != -1) {
baos.write(tmpseqs, 0, read);
}
seqs = baos.toByteArray();
baos.close();
tmpseqs = null;
System.gc();
} catch (IOException ex) {
throw new MediaException("unable to realize: fail to read from source");
}
try {
this.setSequence(seqs);
} catch (Exception e) {
throw new MediaException("unable to realize: " + e.getMessage());
}
| public java.lang.String | getContentType()Override getContentType from BasicPlayer
Always return DefaultConfiguration.TONE content type
chkClosed(true);
return DefaultConfiguration.MIME_AUDIO_TONE;
| public void | setSequence(byte[] sequence)Sets the tone sequence.
if (this.getState() >= Player.PREFETCHED)
throw new IllegalStateException("cannot set seq after prefetched");
if(sequence == null) throw new IllegalArgumentException("null sequence");
if (sequence.length == 0) throw new IllegalArgumentException("empty sequence");
nFlushBuffer(hNative);
if(-1 == nBuffering(hNative, sequence, sequence.length))
throw new IllegalArgumentException("invalid sequence");
if(-1 == nBuffering(hNative, sequence, -1))
throw new IllegalArgumentException("invalid sequence");
hasToneSequenceSet = true;
|
|