1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
---
title: 'HTMLMediaElement: timeupdate'
slug: Web/API/HTMLMediaElement/timeupdate_event
tags:
- Audio
- Event
- HTMLMediaElement
- Reference
- Video
translation_of: Web/API/HTMLMediaElement/timeupdate_event
---
<div>{{APIRef("HTMLMediaElement")}}</div>
<p>当<code>currentTime</code>更新时会触发<code>timeupdate</code>事件。</p>
<p>这个事件的触发频率由系统决定,但是会保证每秒触发4-66次(前提是每次事件处理不会超过250ms)。鼓励用户代理根据系统的负载和处理事件的平均成本来改变事件的频率,保证UI更新不会影响视频的解码。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Bubbles</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Cancelable</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Interface</th>
<td>{{DOMxRef("Event")}}</td>
</tr>
<tr>
<th scope="row">Target</th>
<td>Element</td>
</tr>
<tr>
<th scope="row">Default Action</th>
<td>None</td>
</tr>
<tr>
<th scope="row">Event handler property</th>
<td>{{domxref("GlobalEventHandlers.ontimeupdate")}}</td>
</tr>
<tr>
<th scope="row">Specification</th>
<td>
<p><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#event-media-playing">HTML5 media</a></p>
</td>
</tr>
</tbody>
</table>
<h2 id="示例">示例</h2>
<p>These examples add an event listener for the HTMLMediaElement's <code>timeupdate</code> event, then post a message when that event handler has reacted to the event firing. Remember, the event frequency is dependant on the system load.</p>
<p>Using <code>addEventListener()</code>:</p>
<pre class="brush: js notranslate">const video = document.querySelector('video');
video.addEventListener('timeupdate', (event) => {
console.log('The currentTime attribute has been updated. Again.');
});</pre>
<p>Using the <code>ontimeupdate</code> event handler property:</p>
<pre class="brush: js notranslate">const video = document.querySelector('video');
video.ontimeupdate = (event) => {
console.log('The currentTime attribute has been updated. Again.');
};</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('HTML WHATWG', "media.html#event-media-timeupdate", "timeupdate media event")}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C', "embedded-content-0.html#event-media-timeupdate", "timeupdate media event")}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容">浏览器兼容</h2>
<p>{{Compat("api.HTMLMediaElement.timeupdate_event")}}</p>
<h2 id="相关事件">相关事件</h2>
<ul>
<li>{{domxref("HTMLMediaElement.playing_event", 'HTMLMediaElement: playing event')}}</li>
<li>{{domxref("HTMLMediaElement.waiting_event", 'HTMLMediaElement: waiting event')}}</li>
<li>{{domxref("HTMLMediaElement.seeking_event", 'HTMLMediaElement: seeking event')}}</li>
<li>{{domxref("HTMLMediaElement.seeked_event", 'HTMLMediaElement: seeked event')}}</li>
<li>{{domxref("HTMLMediaElement.ended_event", 'HTMLMediaElement: ended event')}}</li>
<li>{{domxref("HTMLMediaElement.loadedmetadata_event", 'HTMLMediaElement: loadedmetadata event')}}</li>
<li>{{domxref("HTMLMediaElement.loadeddata_event", 'HTMLMediaElement: loadeddata event')}}</li>
<li>{{domxref("HTMLMediaElement.canplay_event", 'HTMLMediaElement: canplay event')}}</li>
<li>{{domxref("HTMLMediaElement.canplaythrough_event", 'HTMLMediaElement: canplaythrough event')}}</li>
<li>{{domxref("HTMLMediaElement.durationchange_event", 'HTMLMediaElement: durationchange event')}}</li>
<li>{{domxref("HTMLMediaElement.timeupdate_event", 'HTMLMediaElement: timeupdate event')}}</li>
<li>{{domxref("HTMLMediaElement.play_event", 'HTMLMediaElement: play event')}}</li>
<li>{{domxref("HTMLMediaElement.pause_event", 'HTMLMediaElement: pause event')}}</li>
<li>{{domxref("HTMLMediaElement.ratechange_event", 'HTMLMediaElement: ratechange event')}}</li>
<li>{{domxref("HTMLMediaElement.volumechange_event", 'HTMLMediaElement: volumechange event')}}</li>
<li>{{domxref("HTMLMediaElement.suspend_event", 'HTMLMediaElement: suspend event')}}</li>
<li>{{domxref("HTMLMediaElement.emptied_event", 'HTMLMediaElement: emptied event')}}</li>
<li>{{domxref("HTMLMediaElement.stalled_event", 'HTMLMediaElement: stalled event')}}</li>
</ul>
<h2 id="更多">更多</h2>
<ul>
<li>{{domxref("HTMLAudioElement")}}</li>
<li>{{domxref("HTMLVideoElement")}}</li>
<li>{{HTMLElement("audio")}}</li>
<li>{{HTMLElement("video")}}</li>
</ul>
|