View Javadoc

1   package org.rpi.providers;
2   
3   import java.util.Observable;
4   import java.util.Observer;
5   
6   import org.apache.log4j.Logger;
7   import org.openhome.net.device.DvDevice;
8   import org.openhome.net.device.IDvInvocation;
9   import org.openhome.net.device.providers.DvProviderAvOpenhomeOrgTime1;
10  import org.rpi.player.PlayManager;
11  import org.rpi.player.events.EventBase;
12  import org.rpi.player.events.EventDurationUpdate;
13  import org.rpi.player.events.EventTimeUpdate;
14  import org.rpi.utils.Utils;
15  
16  public class PrvTime extends DvProviderAvOpenhomeOrgTime1 implements Observer {
17  
18  	private Logger log = Logger.getLogger(PrvTime.class);
19  
20  	public PrvTime(DvDevice iDevice) {
21  		super(iDevice);
22  		log.debug("Creating CustomTime");
23  		enablePropertyTrackCount();
24  		enablePropertyDuration();
25  		enablePropertySeconds();
26  
27  		setPropertyTrackCount(0);
28  		setPropertyDuration(0);
29  		setPropertySeconds(0);
30  
31  		enableActionTime();
32  		PlayManager.getInstance().observTimeEvents(this);
33  
34  	}
35  
36  	public void setDuration(long duration) {
37  		try {
38  			long trackCount = getPropertyTrackCount();
39  			trackCount++;
40  			propertiesLock();
41  			setPropertyTrackCount(trackCount);
42  			setPropertyDuration(duration);
43  			propertiesUnlock();
44  		} catch (Exception e) {
45  			log.error("Error: setDuration", e);
46  		}
47  	}
48  
49  	public synchronized void setSeconds(long seconds) {
50  		try {
51  			//if ((seconds % 2) == 0) {
52  				//propertiesLock();
53  				setPropertySeconds(seconds);
54  				//propertiesUnlock();
55  			//}
56  		} catch (Exception e) {
57  			log.error("Error: setDetails", e);
58  		}
59  	}
60  
61  	@Override
62  	protected Time time(IDvInvocation paramIDvInvocation) {
63  		log.debug("time" + Utils.getLogText(paramIDvInvocation));
64  		long trackCount = getPropertyTrackCount();
65  		long duration = getPropertyDuration();
66  		long seconds = getPropertySeconds();
67  		Time time = new Time(trackCount, duration, seconds);
68  		return time;
69  	}
70  
71  	@Override
72  	public void update(Observable paramObservable, Object obj) {
73  		EventBase eb = (EventBase) obj;
74  		switch (eb.getType()) {
75  		case EVENTTIMEUPDATED:
76  			EventTimeUpdate et = (EventTimeUpdate) eb;
77  			setSeconds(et.getTime());
78  			break;
79  		case EVENTDURATIONUPDATE:
80  			EventDurationUpdate ed = (EventDurationUpdate) eb;
81  			setDuration(ed.getDuration());
82  			break;
83  		}
84  
85  	}
86  
87  }