@Override
 public void read(Buffer buf) {
   if (position < demux.getFrameCount()) {
     buf.setFlagsTo(KEYFRAME);
     if (!(buf.data instanceof BitmapImage)) {
       buf.data = demux.createCompatibleBitmap();
     }
     demux.readFrame((int) position, (BitmapImage) buf.data);
     buf.sampleDuration = new Rational(demux.getDuration((int) position), demux.getJiffies());
     position++;
   } else {
     buf.setFlagsTo(DISCARD);
   }
 }
 @Override
 public long getSampleCount() {
   return demux.getFrameCount();
 }