View Javadoc

1   package org.rpi.player;
2   
3   import org.apache.log4j.Logger;
4   
5   /**
6    * Needed because some control points when playing a track will send a seekId
7    * and a play request, most control points just send a seekId The theory is that
8    * we measure the time between the seekId and play request, if it is very short
9    * we ignore the play request, because the seekId is enough to play our track. * 
10   * 
11   * @author phoyle
12   * 
13   */
14  
15  public class CommandTracker {
16  	
17  	private Logger log = Logger.getLogger(this.getClass());
18  
19  	private long last_time = 0;
20  	private String last_command = "";
21  
22  	public boolean setRequest(String s) {
23  		boolean res = true;
24  		long now = System.currentTimeMillis();
25  		if (last_command.toUpperCase().startsWith("SEEK")) {
26  			if (s.equalsIgnoreCase("PLAY")) {	
27  				long time_span = now - last_time;
28  				if (time_span < 1000) {
29  					log.debug("Ignore this request: " + s + " Time since Seek: " + time_span );
30  					res = false;
31  				}
32  			}
33  		}
34  		last_time = now;
35  		last_command=s;
36  		return res;
37  	}
38  
39  }