HTMLMediaElement

HTMLMediaElement

概述

HTMLMediaElement 是 Aspose.Html FOSS 中用于 Python 的类。继承自:HTMLElement。

用于 HTML 媒体元素的基类(<audio> / <video>)。

此类在 Python 程序中提供 83 个用于操作 HTMLMediaElement 对象的方法。可用的方法包括:__init__、add_event_listener、add_text_track、after、append、append_child、attach_shadow、before、blur、can_play_type、check_visibility、click,以及另外 71 个方法。所有公共成员在安装 Aspose.Html FOSS for Python 包后,可供任何 Python 应用程序访问。属性:access_key、access_key_label、assigned_slot、attributes、audio_tracks、auto_play,以及另外 92 项。

属性

名称类型访问描述
srcstr读取缺失时为 '',否则为 src 属性值。
current_srcstr读取当前选定的源 URL(存根,始终为 '')。
auto_playbool读取对 autoplay 属性的布尔反射。
controlsbool读取对 controls 属性的布尔反射。
loopbool读取对 loop 属性的布尔反射。
mutedbool读取对 muted 属性的布尔反射。
preloadstr读取preload 属性的值,若不存在则为 ''。
cross_origin`strNone`读取
pausedbool读取播放暂停状态(存根,始终为 True)。
endedbool读取播放结束状态(存根,始终为 False)。
durationfloat读取媒体时长(秒)(存根,始终为 NaN)。
current_timefloat读写当前播放位置(秒)(存根,始终为 0.0)。
volumefloat读写音频音量级别(存根,始终为 1.0)。
default_mutedbool读取默认静音状态反映自 muted 属性。
ready_stateint读取就绪状态(存根,始终 0 = HAVE_NOTHING)。
network_stateint读取网络状态(存根,始终 0 = NETWORK_EMPTY)。
buffered"_TimeRanges"读取已缓冲的时间范围 (存根, 始终为空).
played"_TimeRanges"读取已播放的时间范围 (存根, 始终为空).
seekable"_TimeRanges"读取可跳转的时间范围 (存根, 始终为空).
seekingbool读取元素当前是否正在寻找(存根,始终为 False)。
default_playback_ratefloat读写默认播放速率(无头默认 1.0)。
playback_ratefloat读写当前播放速率(无头默认 1.0)。
media_keysNone读取关联的 MediaKeys 对象 (存根,始终为 None).
src_objectNone读取关联的 MediaStream/Blob (存根,始终为 None).
errorNone读取上一次媒体错误(存根,始终为 None)。
text_tracks"_EmptyTrackList"读取文本轨道列表(存根,始终为空)。
audio_tracks"_EmptyTrackList"读取音频轨道列表(存根,始终为空)。
video_tracks"_EmptyTrackList"读取视频轨道列表(存根,始终为空)。
hiddenbool读写元素是否隐藏(反映 hidden 布尔属性)。
titlestr读写此元素的工具提示标题(反映 title 属性)。
langstr读写元素内容的语言(反映 lang 属性)。
tab_indexint读写此元素的制表顺序索引(反映 tabindex 属性)。
access_keystr读写此元素的键盘快捷键(反映 accesskey
    attribute). |

| content_editable | str | 读/写 | 反映 contenteditable 属性(WHATWG HTML §6.6)。 | | is_content_editable | bool | 只读 | 该元素当前是否可编辑(WHATWG HTML §6.6)。 | | dir | str | 读/写 | 元素的文本方向(反映 dir 属性)。 | | draggable | bool | 读/写 | 元素是否可拖动(反映 draggable 属性)。 | | spell_check | bool | 读/写 | 是否启用拼写检查(反映 spellcheck 属性)。 | | spellcheck | bool | 读/写 | 是否启用拼写检查(反映 spellcheck 属性)。 | | autocapitalize | str | 读/写 | 自动大写提示(反映 autocapitalize 属性)。 | | nonce | str | 读/写 | CSP 的加密随机数(反映 nonce 属性)。 | | autofocus | bool | 读/写 | 该元素在页面加载时是否应获得焦点。 | | access_key_label | str | 只读 | 系统分配的访问键标签(无头存根:始终为 '')。 | | input_mode | str | 读/写 | 虚拟键盘输入模式提示(反映 inputmode 属性)。 | | enter_key_hint | str | 读/写 | 回车键操作标签提示(反映 enterkeyhint 属性)。 | | translate | bool | 读/写 | 该元素是否启用翻译(WHATWG HTML §6.1.2)。 | | inner_text | str | 读/写 | 渲染的文本内容 —— 空白折叠 text_content。 | | outer_text | str | 读/写 | 同 inner_text(getter 镜像 inner_text,依据 HTML 标准 §3.2.7)。 | | popover | | Read/Write | Reflects thepopovercontent attribute (WHATWG HTML §6.12). | | node_name|str| Read | The qualified tag name (uppercase for HTML elements). | |tag_name|str| Read | The qualified tag name in uppercase (HTML elements). | |local_name|str| Read | The local part of the qualified name (lowercase). | |namespace_uri|str | None | Read | The namespace URI, orNonefor no namespace. | | style_sheets|“StyleSheetList”| Read | Live stylesheet list applicable to this element's document. | |prefix|str | None | Read | The namespace prefix, orNone. | | id|str| Read | The value of theidattribute, or’’if not present. | | class_name|str | Read | The value of theclassattribute, or’’. | | class_list|“DOMTokenList”| Read | Live mutable set of CSS class tokens backed by theclassattribute. | | dataset|“DOMStringMap” | Read | Live dict-like view of the element'sdata-*custom attributes. | | attributes|NamedNodeMap| Read | The ordered map of Attr objects for this element. | |children|HTMLCollection| Read | A live HTMLCollection of Element-type children only. | |first_element_child|Element | None | Read | The first Element child, orNone. | | last_element_child|Element | None| Read | The last Element child, orNone. | | next_element_sibling|Element | None| Read | The next sibling that is an Element, orNone. | | previous_element_sibling|Element | None| Read | The previous sibling that is an Element, orNone. | | child_element_count|int| Read | The number of Element children. | |inner_html|str| Read/Write | The serialised HTML content of all children (innerHTML). | |outer_html|str| Read/Write | The serialised HTML of this element and all its descendants (outerHTML). | |text_content|str | None| Read/Write | The concatenation of all descendant Text node data (DFS order). | |style|“CSSStyleDeclaration”| Read | The inline style of this element as a live CSSStyleDeclaration. | |scroll_width|int| Read | Content scroll width in CSS pixels (stub: 0). | |scroll_height|int| Read | Content scroll height in CSS pixels (stub: 0). | |client_width|int| Read | Inner width including padding, excluding border (stub: 0). | |client_height|int| Read | Inner height including padding, excluding border (stub: 0). | |scroll_top|int| Read/Write | Vertical scroll offset in CSS pixels (stub: 0). | |scroll_left|int| Read/Write | Horizontal scroll offset in CSS pixels (stub: 0). | |offset_width|int| Read | Layout border-box width in CSS pixels (stub: 0). | |offset_height|int| Read | Layout border-box height in CSS pixels (stub: 0). | |offset_top|int| Read | Top offset fromoffsetParentin CSS pixels (stub: 0). | | offset_left|int | Read | Left offset fromoffsetParentin CSS pixels (stub: 0). | | offset_parent|None | Read | The offset parent element; alwaysNonein headless mode. | | client_top|int | Read | Width of the top CSS border in pixels; always0in headless mode. | | client_left|int | Read | Width of the left CSS border in pixels; always0in headless mode. | | part|“DOMTokenList” | Read | Live DOMTokenList reflecting the elementpartattribute. | | shadow_root | | 只读 | 在无头模式下始终 None。 | | slot | str | 读/写 | 反映 slot 内容属性(DOM §4.2.3)。 | | assigned_slot | | Read | AlwaysNonein headless mode. | | node_type|int | Read | Integer node type constant fromNodeType. | | node_value|str | None| Read/Write | Character data for CharacterData nodes;Noneotherwise. | | parent_node|Node | None | Read | The parent node, orNoneif this node has no parent. | | parent_element|Element | None | Read | The parent node if it is an Element;Noneotherwise. | | is_connected|bool| Read | Whether this node is part of a document's node tree (WHATWG DOM §4.4). | |owner_document|Document | None | Read | The Document this node belongs to, orNonefor Document itself. | | child_nodes|NodeList| Read | A live NodeList of all child nodes. | |first_child|Node | None | Read | The first child node, orNone. | | last_child|Node | None| Read | The last child node, orNone. | | previous_sibling|Node | None| Read | The preceding sibling node, orNone. | | next_sibling|Node | None| Read | The following sibling node, orNone``.

方法

签名描述
play()开始播放(存根无操作)。
pause()暂停播放(存根无操作)。
load()重新加载媒体资源选择(存根无操作)。
can_play_type(type: str) → str返回 '' — 无头模式无法播放任何媒体类型。
add_text_track(kind: str, label: str, language: str)添加文本轨道(存根无操作,返回 None)。
click()在此元素上分派一个合成点击事件。
`focus(options: “dictNone”)`
blur()在此元素上分派一个非冒泡的 'blur' 事件。
show_popover()将此元素显示为弹出框(在无头模式下为无操作)。
hide_popover()隐藏此元素的弹出框(在无头模式下为无操作)。
`toggle_popover(force: “boolNone”)→bool`
`init(local_name: str, namespace_uri: strNone, prefix: str
get_computed_style() → "ComputedStyleDeclaration"返回此元素的 phase-2 cascade-resolved declarations。
insert_adjacent_html(position: str, html: str)在此元素相对位置插入已解析的 HTML 标记。
insert_adjacent_text(position: str, text: str)在此元素相对位置插入文本节点。
`insert_adjacent_element(position: str, element: “ElementNone”)→“Element
get_attribute(name: str) → `strNone`
set_attribute(name: str, value: str)设置属性 name to value, 如果不存在则创建。
remove_attribute(name: str)删除属性 name.
has_attribute(name: str) → boolReturn True 如果属性 name 存在于此元素上。
get_attribute_node(name: str) → `“AttrNone”`
set_attribute_node(attr: "Attr") → `“AttrNone”`
remove_attribute_node(attr: "Attr") → "Attr"Remove attr 从此元素的属性集合中获取并返回它。
`get_attribute_node_ns(namespace_uri: strNone, local_name: str)→“Attr
set_attribute_node_ns(attr: "Attr") → `“AttrNone”`
`remove_attribute_node_ns(namespace_uri: strNone, local_name: str)→“Attr”`
`get_attribute_ns(namespace_uri: strNone, local_name: str)→str
`set_attribute_ns(namespace_uri: strNone, qualified_name: str, value: str)`
`has_attribute_ns(namespace_uri: strNone, local_name: str)→bool`
`remove_attribute_ns(namespace_uri: strNone, local_name: str)`
`toggle_attribute(name: str, force: boolNone)→bool`
get_attribute_names() → list[str]返回所有属性的限定名称,按收集顺序。
has_attributes() → bool当此元素具有一个或多个属性时,返回 True。
`scroll_into_view(arg: booldict
`scroll(x_or_options: floatdict
scroll_into_view_if_needed(center_if_needed: bool)如果该元素尚未可见,则将其滚动至视图中(在无头模式下为无操作)。
set_pointer_capture(pointer_id: int)将此元素指定为给定指针的捕获目标(无操作)。
release_pointer_capture(pointer_id: int)释放给定指针 ID 的指针捕获(无操作)。
has_pointer_capture(pointer_id: int) → bool返回此元素是否对给定 ID 拥有指针捕获。
request_pointer_lock()请求将指针锁定到此元素(无操作)。
`request_fullscreen(options: “dictNone”)`
`check_visibility(options: “dictNone”)→bool`
query_selector(selector: str) → `ElementNone`
query_selector_all(selector: str) → NodeList返回一个静态的 NodeList,包含所有匹配的元素 selector.
matches(selector: str) → boolReturn True 如果此元素匹配 CSS selector.
webkit_matches_selector(selector: str) → bool浏览器兼容别名,针对 :meth:matches。
closest(selector: str) → `“ElementNone”`
get_elements_by_tag_name(qualified_name: str) → HTMLCollection返回所有标签名匹配的后代元素 qualified_name.
get_elements_by_class_name(class_names: str) → HTMLCollection返回所有拥有给定所有类标记的后代元素。
filter_fn(el: "Element") → bool在此 HTMLMediaElement 实例上调用 filter_fn(el)。
remove()将此元素从其父节点中移除。
before()Insert nodes 在其父节点中紧靠此元素之前。
after()Insert nodes 在其父元素中紧接此元素之后。
replace_with()将此元素替换为 nodes 在其父元素中。
prepend()Insert nodes 在此元素的第一个子元素之前。
append()Append nodes 作为此元素的最后子元素。
replace_children()移除所有子元素,然后追加 nodes 作为新的子元素。
get_bounding_client_rect() → "DOMRect"返回边界客户端矩形(全零存根)。
get_client_rects() → "DOMRectList"返回客户端矩形列表(在服务器端上下文中为空)。
get_animations() → list[object]返回此元素的活动动画(无头存根:始终为 [])。
`attach_shadow(init: “dictNone”)`
get_root_node(composed: bool) → "Node"返回节点树的根节点。
has_child_nodes() → bool返回此节点是否至少拥有一个直接子节点。
`lookup_namespace_uri(prefix: strNone)→str
`lookup_prefix(namespace_uri: strNone)→str
`is_default_namespace(namespace_uri: strNone)→bool`
`is_supported(feature: str, version: strNone)→bool`
`get_feature(feature: str, version: strNone)→object
`set_user_data(key: str, data: objectNone, handler: object
get_user_data(key: str) → `objectNone`
append_child(node: Node) → NodeAppend node 作为此节点的最后一个子节点。
`insert_before(node: Node, reference: NodeNone)→Node`
remove_child(node: Node) → NodeRemove node 从子列表中取出并返回它。
replace_child(new_child: Node, old_child: Node) → NodeReplace old_child with new_child.
clone_node(deep: bool) → Node返回此节点的副本。
normalize()将此节点及其整个子树置于规范形式。
`contains(other: NodeNone)→bool`
compare_document_position(other: "Node") → int返回描述位置的位掩码 other 相对于此节点。
`is_equal_node(other: NodeNone)→bool`
`is_same_node(other_node: NodeNone)→bool`
add_event_listener(type: str, listener: Callable, capture: bool, once: bool)Register listener 针对事件的 type.
remove_event_listener(type: str, listener: Callable, capture: bool)取消注册先前已注册的监听器。
dispatch_event(event: "Event") → boolDispatch event 通过祖先树。

另请参阅

 中文