public boolean doPlayerPrefetch() {
// Has the data already been prefetched?
if( ! prefetchNeeded ) return true;
Vector frameVector = new Vector();
DataInputStream in = null;
try {
// Create an input stream
in = new DataInputStream(
new PullSourceInputStream(stream) );
// Load every image, first processing the image
// length and frame delay in the header
try {
while(true) {
// Get frame length
long length = in.readLong();
// Get frame delay
long nanos = in.readLong();
// Get frame image
byte[] b = new byte[(int)length];
in.readFully(b,0,(int)length);
ImageIcon icon = new ImageIcon(b);
// Update CachingControl
cache.addToProgress(16 + length);
// Create MultiImageFrame object
MultiImageFrame m = new MultiImageFrame(icon, nanos);
frameVector.addElement(m);
}
}
// Read until EOF
catch(EOFException e) {
cache.setDone();
}
}
catch(IOException e) {
System.err.println("I/O Error reading data");
postEvent(
new ResourceUnavailableEvent(this,
"I/O error occurred while reading data stream") );
return false;
}
finally {
try { in.close(); } catch(Exception e) {}
}
// Convert the vector to an array and set the frames
MultiImageFrame[] frames = new MultiImageFrame[frameVector.size()];
frameVector.copyInto(frames);