Class: Rabbit::VideoWindow::VideoWidget

Inherits:
Gtk::DrawingArea
  • Object
show all
Defined in:
lib/rabbit/video-window.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ VideoWidget

Returns a new instance of VideoWidget.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rabbit/video-window.rb', line 77

def initialize(file)
  super()

  @playbin = Gst::ElementFactory.make('playbin2')

  @video = Gst::ElementFactory.make('xvimagesink')
  @video.force_aspect_ratio = true

  @playbin.video_sink = @video
  @playbin.audio_sink = Gst::ElementFactory.make('autoaudiosink')
  @playbin.signal_connect('notify') do
    @playbin.video_sink.xwindow_id = self.window.xid if self.window
    @playbin.video_sink.expose
  end
  @playbin.uri = "file://#{File.absolute_path(file)}"
  @playbin.ready
end

Instance Method Details

#pauseObject



100
101
102
103
# File 'lib/rabbit/video-window.rb', line 100

def pause
  @playbin.pause
  @playing = false
end

#playObject



95
96
97
98
# File 'lib/rabbit/video-window.rb', line 95

def play
  @playbin.play
  @playing = true
end

#seek(time) ⇒ Object



110
111
112
113
114
115
# File 'lib/rabbit/video-window.rb', line 110

def seek(time)
  @playbin.seek(1.0, Gst::Format::TIME,
    Gst::Seek::FLAG_FLUSH | Gst::Seek::FLAG_KEY_UNIT,
    Gst::Seek::TYPE_CUR, time * Gst::SECOND,
    Gst::Seek::TYPE_NONE, -1);
end

#stopObject



105
106
107
108
# File 'lib/rabbit/video-window.rb', line 105

def stop
  @playbin.stop
  @playing = false
end

#toggleObject



117
118
119
# File 'lib/rabbit/video-window.rb', line 117

def toggle
  @playing ? pause : play
end