7d3e570b17dce1c31c7f0c3e675386199e1a0da9
[euphoria.git] / lib / playtime_updater.rb
1 # $Id: playtime_updater.rb,v 1.4 2005/07/07 16:33:55 tsauerbeck Exp $
2
3 class PlaytimeUpdater
4         INTERVAL = 0.25
5
6         def initialize(xmms, &block)
7                 @xmms = xmms
8                 @block = block
9                 @timer = nil
10                 @current_pos = nil
11
12                 on_timer
13         end
14
15         def enabled=(v)
16         if !v && !@timer.nil?
17                         @timer.delete
18                         @timer = nil
19                 elsif v
20                         @current_pos = nil
21                         on_timer
22
23             @timer = Ecore::Timer.new(INTERVAL) do
24                                 on_timer
25                                 true
26                         end
27         end
28         end
29
30         private
31         def on_timer
32                 pltime = @xmms.playback_playtime.wait.value
33                 cur_pos = pltime / 1000
34
35                 if @current_pos != cur_pos
36                         @current_pos = cur_pos
37                         @block.call(@current_pos)
38                 end
39         end
40 end