Class: Dommy::HTMLMediaElement

Inherits:
HTMLElement show all
Defined in:
lib/dommy/html_elements.rb

Overview

‘<audio>` / `<video>` shared base. The actual media engine is absent in Dommy — getters return inert values, `play()` returns a resolved Promise, and `pause()` flips `paused` back to true.

Direct Known Subclasses

HTMLAudioElement, HTMLVideoElement

Constant Summary collapse

NETWORK_EMPTY =
0
NETWORK_IDLE =
1
NETWORK_LOADING =
2
NETWORK_NO_SOURCE =
3
HAVE_NOTHING =
0
HAVE_METADATA =
1
HAVE_CURRENT_DATA =
2
HAVE_FUTURE_DATA =
3
HAVE_ENOUGH_DATA =
4

Constants inherited from Element

Element::ATTRIBUTE_NODE, Element::CDATA_SECTION_NODE, Element::COMMENT_NODE, Element::DOCUMENT_FRAGMENT_NODE, Element::DOCUMENT_NODE, Element::DOCUMENT_POSITION_CONTAINED_BY, Element::DOCUMENT_POSITION_CONTAINS, Element::DOCUMENT_POSITION_DISCONNECTED, Element::DOCUMENT_POSITION_FOLLOWING, Element::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, Element::DOCUMENT_POSITION_PRECEDING, Element::DOCUMENT_TYPE_NODE, Element::ELEMENT_NODE, Element::PROCESSING_INSTRUCTION_NODE, Element::SHADOW_HOST_TAGS, Element::TEXT_NODE

Constants included from Node

Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAGMENT_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_POSITION_CONTAINED_BY, Node::DOCUMENT_POSITION_CONTAINS, Node::DOCUMENT_POSITION_DISCONNECTED, Node::DOCUMENT_POSITION_FOLLOWING, Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, Node::DOCUMENT_POSITION_PRECEDING, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE

Instance Attribute Summary

Attributes inherited from Element

#__node__, #document

Instance Method Summary collapse

Methods inherited from Element

#[], #[]=, #__shadow_root__, #after, #anchor_href, #append, #append_child, #attach_shadow, #attributes, #base_uri, #before, #blur, #child_element_count, #child_nodes, #children, #class_list, #class_name, #class_name=, #click, #clone_node, #closest, #compare_document_position, #contains?, #dataset, #equal_node?, #first_child, #first_element_child, #focus, #get_attribute, #get_attribute_node, #get_elements_by_class_name, #get_elements_by_tag_name, #get_html, #get_inner_html, #has_attribute?, #has_attributes?, #has_child_nodes?, #id, #id=, #initialize, #inner_html, #inner_html=, #insert_adjacent_element, #insert_adjacent_html, #insert_adjacent_text, #insert_before, #is_connected?, #last_child, #last_element_child, #live_child_nodes, #local_name, #matches?, #namespace_uri, #next_element_sibling, #next_sibling, #normalize, #on, #outer_html, #outer_html=, #owner_document, #parent_element, #parent_node, #prepend, #previous_element_sibling, #previous_sibling, #query_selector, #query_selector_all, #reflected_attr_name, #remove, #remove_attribute, #remove_attribute_node, #remove_child, #replace_child, #replace_children, #replace_with_nodes, #role, #role=, #root_node, #same_node?, #set_attribute, #set_attribute_node, #shadow_root, #slot, #slot=, #style, #tag_name, #text_content, #text_content=, #to_s, #toggle_attribute

Methods included from EventTarget

#__deliver_event__, #add_event_listener, #dispatch_event, #invoke_listener, #remove_event_listener

Constructor Details

This class inherits a constructor from Dommy::Element

Instance Method Details

#__js_call__(method, args) ⇒ Object



3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
# File 'lib/dommy/html_elements.rb', line 3324

def __js_call__(method, args)
  case method
  when "play"
    play
  when "pause"
    pause
  when "load"
    load
  when "canPlayType"
    can_play_type(args[0])
  else
    super
  end
end

#__js_get__(key) ⇒ Object



3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
# File 'lib/dommy/html_elements.rb', line 3232

def __js_get__(key)
  case key
  when "src"
    src
  when "currentSrc"
    current_src
  when "preload"
    preload
  when "crossOrigin"
    crossorigin
  when "autoplay"
    autoplay
  when "loop"
    loop_
  when "controls"
    controls
  when "muted"
    muted
  when "defaultMuted"
    default_muted
  when "paused"
    paused
  when "ended"
    ended
  when "seeking"
    seeking
  when "volume"
    volume
  when "playbackRate"
    playback_rate
  when "defaultPlaybackRate"
    default_playback_rate
  when "currentTime"
    current_time
  when "duration"
    duration
  when "networkState"
    network_state
  when "readyState"
    ready_state
  when "NETWORK_EMPTY"
    NETWORK_EMPTY
  when "NETWORK_IDLE"
    NETWORK_IDLE
  when "NETWORK_LOADING"
    NETWORK_LOADING
  when "NETWORK_NO_SOURCE"
    NETWORK_NO_SOURCE
  when "HAVE_NOTHING"
    HAVE_NOTHING
  when "HAVE_METADATA"
    HAVE_METADATA
  when "HAVE_CURRENT_DATA"
    HAVE_CURRENT_DATA
  when "HAVE_FUTURE_DATA"
    HAVE_FUTURE_DATA
  when "HAVE_ENOUGH_DATA"
    HAVE_ENOUGH_DATA
  else
    super
  end
end

#__js_set__(key, value) ⇒ Object



3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
# File 'lib/dommy/html_elements.rb', line 3295

def __js_set__(key, value)
  case key
  when "src"
    self.src = value
  when "preload"
    self.preload = value
  when "autoplay"
    self.autoplay = value
  when "loop"
    self.loop_ = value
  when "controls"
    self.controls = value
  when "muted"
    self.muted = value
  when "defaultMuted"
    self.default_muted = value
  when "volume"
    self.volume = value
  when "playbackRate"
    self.playback_rate = value
  when "defaultPlaybackRate"
    self.default_playback_rate = value
  when "currentTime"
    self.current_time = value
  else
    super
  end
end

#autoplayObject



3115
3116
3117
# File 'lib/dommy/html_elements.rb', line 3115

def autoplay
  reflected_boolean("autoplay")
end

#autoplay=(v) ⇒ Object



3119
3120
3121
# File 'lib/dommy/html_elements.rb', line 3119

def autoplay=(v)
  set_reflected_boolean("autoplay", v)
end

#can_play_type(_type) ⇒ Object



3227
3228
3229
3230
# File 'lib/dommy/html_elements.rb', line 3227

def can_play_type(_type)
  # spec: "" | "maybe" | "probably". We don't decode → "".
  ""
end

#controlsObject



3131
3132
3133
# File 'lib/dommy/html_elements.rb', line 3131

def controls
  reflected_boolean("controls")
end

#controls=(v) ⇒ Object



3135
3136
3137
# File 'lib/dommy/html_elements.rb', line 3135

def controls=(v)
  set_reflected_boolean("controls", v)
end

#crossoriginObject



3111
3112
3113
# File 'lib/dommy/html_elements.rb', line 3111

def crossorigin
  reflected_string("crossorigin")
end

#current_srcObject



3099
3100
3101
# File 'lib/dommy/html_elements.rb', line 3099

def current_src
  src
end

#current_timeObject



3191
3192
3193
# File 'lib/dommy/html_elements.rb', line 3191

def current_time
  @__current_time.to_f
end

#current_time=(v) ⇒ Object



3195
3196
3197
# File 'lib/dommy/html_elements.rb', line 3195

def current_time=(v)
  @__current_time = v.to_f
end

#default_mutedObject



3147
3148
3149
# File 'lib/dommy/html_elements.rb', line 3147

def default_muted
  reflected_boolean("muted")
end

#default_muted=(v) ⇒ Object



3151
3152
3153
# File 'lib/dommy/html_elements.rb', line 3151

def default_muted=(v)
  set_reflected_boolean("muted", v)
end

#default_playback_rateObject



3183
3184
3185
# File 'lib/dommy/html_elements.rb', line 3183

def default_playback_rate
  @__default_rate.nil? ? 1.0 : @__default_rate
end

#default_playback_rate=(v) ⇒ Object



3187
3188
3189
# File 'lib/dommy/html_elements.rb', line 3187

def default_playback_rate=(v)
  @__default_rate = v.to_f
end

#durationObject



3199
3200
3201
# File 'lib/dommy/html_elements.rb', line 3199

def duration
  Float::NAN
end

#endedObject



3159
3160
3161
# File 'lib/dommy/html_elements.rb', line 3159

def ended
  false
end

#loadObject



3223
3224
3225
# File 'lib/dommy/html_elements.rb', line 3223

def load
  nil
end

#loop_Object



3123
3124
3125
# File 'lib/dommy/html_elements.rb', line 3123

def loop_
  reflected_boolean("loop")
end

#loop_=(v) ⇒ Object



3127
3128
3129
# File 'lib/dommy/html_elements.rb', line 3127

def loop_=(v)
  set_reflected_boolean("loop", v)
end

#mutedObject



3139
3140
3141
# File 'lib/dommy/html_elements.rb', line 3139

def muted
  @__muted == true || reflected_boolean("muted")
end

#muted=(v) ⇒ Object



3143
3144
3145
# File 'lib/dommy/html_elements.rb', line 3143

def muted=(v)
  @__muted = !!v
end

#network_stateObject



3203
3204
3205
# File 'lib/dommy/html_elements.rb', line 3203

def network_state
  NETWORK_EMPTY
end

#pauseObject



3218
3219
3220
3221
# File 'lib/dommy/html_elements.rb', line 3218

def pause
  @__paused = true
  nil
end

#pausedObject



3155
3156
3157
# File 'lib/dommy/html_elements.rb', line 3155

def paused
  @__paused.nil? ? true : @__paused
end

#playObject



3211
3212
3213
3214
3215
3216
# File 'lib/dommy/html_elements.rb', line 3211

def play
  @__paused = false
  promise = PromiseValue.new(@document.default_view)
  promise.fulfill(nil)
  promise
end

#playback_rateObject



3175
3176
3177
# File 'lib/dommy/html_elements.rb', line 3175

def playback_rate
  @__rate.nil? ? 1.0 : @__rate
end

#playback_rate=(v) ⇒ Object



3179
3180
3181
# File 'lib/dommy/html_elements.rb', line 3179

def playback_rate=(v)
  @__rate = v.to_f
end

#preloadObject



3103
3104
3105
# File 'lib/dommy/html_elements.rb', line 3103

def preload
  reflected_string("preload")
end

#preload=(v) ⇒ Object



3107
3108
3109
# File 'lib/dommy/html_elements.rb', line 3107

def preload=(v)
  set_reflected_string("preload", v)
end

#ready_stateObject



3207
3208
3209
# File 'lib/dommy/html_elements.rb', line 3207

def ready_state
  HAVE_NOTHING
end

#seekingObject



3163
3164
3165
# File 'lib/dommy/html_elements.rb', line 3163

def seeking
  false
end

#srcObject



3091
3092
3093
# File 'lib/dommy/html_elements.rb', line 3091

def src
  reflected_string("src")
end

#src=(v) ⇒ Object



3095
3096
3097
# File 'lib/dommy/html_elements.rb', line 3095

def src=(v)
  set_reflected_string("src", v)
end

#volumeObject



3167
3168
3169
# File 'lib/dommy/html_elements.rb', line 3167

def volume
  @__volume.nil? ? 1.0 : @__volume
end

#volume=(v) ⇒ Object



3171
3172
3173
# File 'lib/dommy/html_elements.rb', line 3171

def volume=(v)
  @__volume = v.to_f
end