新方案关键代码解释
清单一: 实现代码中的主要属性
//单件模式,用来储存截图的缓冲区。
private static Vector bufferVec = null;
//标识缓冲区是否储存固定数目的截图,默认为固定数目。
private boolean isLimitedBuffer = true;
//伪视频所覆盖的自动测试过程,单位为秒;默认情况下存储最近30秒内的截图。
private int videoLength = 30;
//截图的时间间隔,单位为秒;默认情况下每隔1秒执行一次抓屏操作。
private double snapInterval = 1;
//缓冲区容量,该属性值由videoLength和snapInterval共同决定。
private int bufferCapability;
//伪视频输出位置
private String outputLocation = "c:/";
//伪视频格式,即生成的动态图片格式,在本例给出的实现使用了GIF格式。
private String pseudoVideoFormat = ".gif";
//标识生成的伪视频是否循环播放,默认为只播放一次。
private boolean replayIndefinitely = false;
//伪视频的重放速度,可选值为1,2,3。分别表示快速、中速和慢速。
private int replaySpeed = 2;
//标识是否有错误发生。当其值为true时,表明需要立即生成伪视频。
public static boolean errorFlag = false;
清单二: 实现代码中的主要方法
/**
* Create a screenshot pool with limited capability, it only
* stores enough screenshots to create a pseudo-video of appointed length
*
* @param videoLength - length of pseudo-video
* @param snapInterval - interval to scratch screenshots, the unit is second
* @param replayIndefinitely - the video plays once or repeats indefinitely
* @param replaySpeed - play speed of the video,1 means fast,2 is normal,and 3 means slow
*/
public ScreenshotsPool(int videoLength, double snapInterval,
boolean replayIndefinitely, int replaySpeed) {
super();
this.isLimitedBuffer = true;
this.videoLength = videoLength;
this.snapInterval = snapInterval;
this.replayIndefinitely = replayIndefinitely;
//设置有效的回放速度;
if((replaySpeed==1)||(replaySpeed==2)||(replaySpeed==3))