Class: Glimmer::Video

Inherits:
Object
  • Object
show all
Includes:
UI::CustomWidget
Defined in:
lib/views/glimmer/video.rb

Defined Under Namespace

Classes: VideoObserverBrowserFunction

Instance Method Summary collapse

Instance Method Details

#can_handle_observation_request?(observation_request) ⇒ Boolean

Returns:

  • (Boolean)


196
197
198
199
200
201
202
203
204
# File 'lib/views/glimmer/video.rb', line 196

def can_handle_observation_request?(observation_request)
  result = false
  observation_request = observation_request.to_s
  if observation_request.start_with?('on_')
    attribute = observation_request.sub(/^on_/, '')
    result = OBSERVED_ATTRIBUTE_TO_PROPERTY_MAPPING.keys.include?(attribute)
  end
  result || super
end

#durationObject



158
159
160
# File 'lib/views/glimmer/video.rb', line 158

def duration
  video_attribute('duration')
end

#ended?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/views/glimmer/video.rb', line 131

def ended?
  video_attribute('ended')
end

#fast_forward(seconds = 15) ⇒ Object



150
151
152
# File 'lib/views/glimmer/video.rb', line 150

def fast_forward(seconds=15)
  self.position += seconds
end

#file=(a_file) ⇒ Object



97
98
99
100
# File 'lib/views/glimmer/video.rb', line 97

def file=(a_file)
  options[:file] = a_file
  set_video_source
end

#handle_observation_request(observation_request, &block) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/views/glimmer/video.rb', line 206

def handle_observation_request(observation_request, &block)
  observation_request = observation_request.to_s
  if observation_request.start_with?('on_')
    attribute = observation_request.sub(/^on_/, '')
    if attribute == 'loaded' && !@completed
      super('on_completed', &block)
    elsif OBSERVED_ATTRIBUTE_TO_PROPERTY_MAPPING.keys.include?(attribute)
      add_video_observer(block, OBSERVED_ATTRIBUTE_TO_PROPERTY_MAPPING[attribute])
    else
      super
    end
  end
end

#loaded?Boolean

Video fully loaded and ready for playback

Returns:

  • (Boolean)


136
137
138
# File 'lib/views/glimmer/video.rb', line 136

def loaded?
  !!@completed
end

#muteObject



180
181
182
# File 'lib/views/glimmer/video.rb', line 180

def mute
  video_attribute_set('muted', true)
end

#muted?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/views/glimmer/video.rb', line 188

def muted?
  video_attribute('muted')
end

#pauseObject



111
112
113
# File 'lib/views/glimmer/video.rb', line 111

def pause
  video_action('pause')
end

#paused?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'lib/views/glimmer/video.rb', line 123

def paused?
  video_attribute('paused')
end

#playObject



107
108
109
# File 'lib/views/glimmer/video.rb', line 107

def play
  video_action('play')
end

#playing?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/views/glimmer/video.rb', line 127

def playing?
  !paused?
end

#positionObject



140
141
142
# File 'lib/views/glimmer/video.rb', line 140

def position
  video_attribute('currentTime')
end

#position=(new_position) ⇒ Object



144
145
146
147
148
# File 'lib/views/glimmer/video.rb', line 144

def position=(new_position)
  new_position = [new_position, 0].max
  new_position = [new_position, duration].min
  video_attribute_set('currentTime', new_position)
end

#reloadObject



119
120
121
# File 'lib/views/glimmer/video.rb', line 119

def reload
  video_action('load')
end

#rewind(seconds = 15) ⇒ Object



154
155
156
# File 'lib/views/glimmer/video.rb', line 154

def rewind(seconds=15)
  self.position -= seconds
end

#sourceObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/views/glimmer/video.rb', line 74

def source
  file_source = file
  if file_source
    if file_source.start_with?('uri:classloader')
      file_path = file_source.split(/\/\//).last
      file_name = File.basename(file_source)
      # supporting windows ENV['temp'] or mac/unix /tmp
      tmp_dir = ENV['temp'] ? File.expand_path(ENV['temp']) : '/tmp'
      tmp_dir += '/glimmer/lib/glimmer/ui/video'
      FileUtils.mkdir_p(tmp_dir)
      tmp_file = File.join(tmp_dir, file_name)
      file_content = File.binread(file_source) rescue File.binread(file_path)
      File.binwrite(tmp_file, file_content)
      "file://#{tmp_file}"
    else
      file_source = File.expand_path(file_source)
      "file://#{file_source}"
    end
  else
    url
  end
end

#toggleObject



115
116
117
# File 'lib/views/glimmer/video.rb', line 115

def toggle
  paused? ? play : pause
end

#toggle_mutedObject



192
193
194
# File 'lib/views/glimmer/video.rb', line 192

def toggle_muted
  muted? ? unmute : mute
end

#unmuteObject



184
185
186
# File 'lib/views/glimmer/video.rb', line 184

def unmute
  video_attribute_set('muted', false)
end

#url=(a_url) ⇒ Object



102
103
104
105
# File 'lib/views/glimmer/video.rb', line 102

def url=(a_url)
  options[:url] = a_url
  set_video_source
end

#volumeObject



162
163
164
# File 'lib/views/glimmer/video.rb', line 162

def volume
  video_attribute('volume')
end

#volume=(value) ⇒ Object



166
167
168
169
170
# File 'lib/views/glimmer/video.rb', line 166

def volume=(value)
  value = [value, 0].max
  value = [value, 1].min
  video_attribute_set('volume', value)
end

#volume_down(value = 0.05) ⇒ Object



176
177
178
# File 'lib/views/glimmer/video.rb', line 176

def volume_down(value=0.05)
  self.volume -= value
end

#volume_up(value = 0.05) ⇒ Object



172
173
174
# File 'lib/views/glimmer/video.rb', line 172

def volume_up(value=0.05)
  self.volume += value
end