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

JS_METHOD_NAMES =

Own js_call methods, on top of Element’s.

%w[play pause load canPlayType].freeze
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

#document

Instance Method Summary collapse

Methods inherited from HTMLElement

#case_sensitive_attribute_names?

Methods inherited from Element

#[], #[]=, #__dommy_backend_node__, #__internal_shadow_root__, #__test_scroll_log__, #after, #anchor_href, #animate, #append, #append_child, #at_xpath, #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_animations, #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, #path, #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, #xpath

Methods included from EventTarget

#__internal_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



3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
# File 'lib/dommy/html_elements.rb', line 3381

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



3289
3290
3291
3292
3293
3294
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
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
# File 'lib/dommy/html_elements.rb', line 3289

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_method_names__Object



3133
3134
3135
# File 'lib/dommy/html_elements.rb', line 3133

def __js_method_names__
  super + JS_METHOD_NAMES
end

#__js_set__(key, value) ⇒ Object



3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
# File 'lib/dommy/html_elements.rb', line 3352

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



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

def autoplay
  reflected_boolean("autoplay")
end

#autoplay=(v) ⇒ Object



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

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

#can_play_type(_type) ⇒ Object



3284
3285
3286
3287
# File 'lib/dommy/html_elements.rb', line 3284

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

#controlsObject



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

def controls
  reflected_boolean("controls")
end

#controls=(v) ⇒ Object



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

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

#crossoriginObject



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

def crossorigin
  reflected_string("crossorigin")
end

#current_srcObject



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

def current_src
  src
end

#current_timeObject



3248
3249
3250
# File 'lib/dommy/html_elements.rb', line 3248

def current_time
  @__current_time.to_f
end

#current_time=(v) ⇒ Object



3252
3253
3254
# File 'lib/dommy/html_elements.rb', line 3252

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

#default_mutedObject



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

def default_muted
  reflected_boolean("muted")
end

#default_muted=(v) ⇒ Object



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

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

#default_playback_rateObject



3240
3241
3242
# File 'lib/dommy/html_elements.rb', line 3240

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

#default_playback_rate=(v) ⇒ Object



3244
3245
3246
# File 'lib/dommy/html_elements.rb', line 3244

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

#durationObject



3256
3257
3258
# File 'lib/dommy/html_elements.rb', line 3256

def duration
  Float::NAN
end

#endedObject



3216
3217
3218
# File 'lib/dommy/html_elements.rb', line 3216

def ended
  false
end

#loadObject



3280
3281
3282
# File 'lib/dommy/html_elements.rb', line 3280

def load
  nil
end

#loop_Object



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

def loop_
  reflected_boolean("loop")
end

#loop_=(v) ⇒ Object



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

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

#mutedObject



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

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

#muted=(v) ⇒ Object



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

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

#network_stateObject



3260
3261
3262
# File 'lib/dommy/html_elements.rb', line 3260

def network_state
  NETWORK_EMPTY
end

#pauseObject



3275
3276
3277
3278
# File 'lib/dommy/html_elements.rb', line 3275

def pause
  @__paused = true
  nil
end

#pausedObject



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

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

#playObject



3268
3269
3270
3271
3272
3273
# File 'lib/dommy/html_elements.rb', line 3268

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

#playback_rateObject



3232
3233
3234
# File 'lib/dommy/html_elements.rb', line 3232

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

#playback_rate=(v) ⇒ Object



3236
3237
3238
# File 'lib/dommy/html_elements.rb', line 3236

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

#preloadObject



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

def preload
  reflected_string("preload")
end

#preload=(v) ⇒ Object



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

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

#ready_stateObject



3264
3265
3266
# File 'lib/dommy/html_elements.rb', line 3264

def ready_state
  HAVE_NOTHING
end

#seekingObject



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

def seeking
  false
end

#srcObject



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

def src
  reflected_string("src")
end

#src=(v) ⇒ Object



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

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

#volumeObject



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

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

#volume=(v) ⇒ Object



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

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