Class: Shoes::Video

Inherits:
Object show all
Defined in:
lib/plugins/video.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Video

Returns a new instance of Video.


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/plugins/video.rb', line 3

def initialize args
  @initials = args
  args.each do |k, v|
    instance_variable_set "@#{k}", v
  end
  Video.class_eval do
    attr_accessor *args.keys
  end
  args[:real].bus.add_watch do |b, message|
    case message.type
      when Gst::Message::EOS
        @eos = true; pause
      when Gst::Message::WARNING, Gst::Message::ERROR
        p message.parse
      when Gst::Message::ELEMENT
        duration = Gst::QueryDuration.new Gst::Format::TIME
        @real.query duration
        @length = duration.parse.last
      else
        #p message.type
    end
    true
  end
  @app.win.signal_connect('destroy'){@real.stop}
  @stime = 0
end

Instance Method Details

#clock_timeObject


93
94
95
# File 'lib/plugins/video.rb', line 93

def clock_time
  @real.clock ? @real.clock.time : 0
end

#lengthObject


63
64
65
# File 'lib/plugins/video.rb', line 63

def length
  @length / 1_000_000 if @length
end

#pauseObject


50
51
52
53
54
55
56
# File 'lib/plugins/video.rb', line 50

def pause
  if @playing
    @real.pause
    @stime = clock_time - @stime
    @playing = false
  end
end

#playObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/plugins/video.rb', line 34

def play
  if @playing
    self.time, @eos = 0, nil
  else
    @stime = clock_time - seek_time
    @ready = @playing  = true
    (self.time, @eos = 0, nil) if @eos
  end
  unless @whdl
    @whdl = @app.win.window.class.method_defined?(:xid) ? @app.win.window.xid : 
      Win32API.new('user32', 'GetForegroundWindow', [], 'N').call
    @real.video_sink.xwindow_id = @whdl
  end
  @real.play
end

#playing?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/plugins/video.rb', line 30

def playing?
  @eos ? false : @playing
end

#positionObject


67
68
69
# File 'lib/plugins/video.rb', line 67

def position
  @length ? time.to_f / length : 0.0
end

#position=(x) ⇒ Object


71
72
73
# File 'lib/plugins/video.rb', line 71

def position=(x)
  self.time = length * x if @length
end

#seek_timeObject


89
90
91
# File 'lib/plugins/video.rb', line 89

def seek_time
  @playing ? clock_time - @stime : @stime
end

#stopObject


58
59
60
61
# File 'lib/plugins/video.rb', line 58

def stop
  @eos = true
  @real.stop
end

#timeObject


75
76
77
# File 'lib/plugins/video.rb', line 75

def time
  seek_time / 1_000_000
end

#time=(ms) ⇒ Object


79
80
81
82
83
84
85
86
87
# File 'lib/plugins/video.rb', line 79

def time=(ms)
  if @ready
    t = ms * 1_000_000
    e = Gst::EventSeek.new 1.0, Gst::Format::TIME, Gst::Seek::FLAG_FLUSH, 
      Gst::SeekType::SET, t, Gst::SeekType::NONE, Gst::ClockTime::NONE
    @real.send_event e
    @stime = @playing ? clock_time - t : t
  end
end