HTMLMediaElement
HTMLMediaElement
インターフェイスは、 HTMLElement
に音声や動画で一般的なメディアに関する基本的な能力の対応に必要なプロパティやメソッドを追加します。 HTMLVideoElement
および HTMLAudioElement
要素はどちらも、このインターフェイスを継承しています。
プロパティ
このインターフェイスは祖先である HTMLElement
, Element
, Node
, EventTarget
のプロパティを継承しています。
HTMLMediaElement.audioTracks
AudioTrackList
で、この要素に含まれるAudioTrack
オブジェクトを列挙します。HTMLMediaElement.autoplay
Boolean
で、 HTML のautoplay
属性の値を反映し、再生に十分なデータが揃った時点で自動的に再生を始めるかどうかを示します。メモ: オーディオ(またはオーディオトラックを含むビデオ)を自動的に再生するサイトは、ユーザーにとって不快なエクスペリエンスになる可能性があるため、可能な限り避ける必要があります。 自動再生機能を実装する必要がある場合、オプトイン(ユーザーに明示的に有効にすること)する必要があります。 ただし、ソースが後でユーザー制御下で実行されるメディア要素をプレ作成する場合、これは便利です。HTMLMediaElement.buffered
読取専用- その時点でブラウザがバッファしたメディアデータの範囲を表す
TimeRanges
オブジェクトを取得できます。 HTMLMediaElement.controller
- 要素に割り当てられた
MediaController
オブジェクトを参照できます。割り当てられていない場合の値はnull
です。 HTMLMediaElement.controls
- 再生をコントロールするユーザインタフェースの表示 / 非表示を指定する
controls
属性を、Boolean
で参照できます。 HTMLMediaElement.controlsList
読取専用- ユーザーエージェントが独自のコントロールセットを表示するたびに、メディア要素に表示するコントロールをユーザーエージェントが選択するのに役立つ
DOMTokenList
を返します。DOMTokenList
は、nodownload
、nofullscreen
、noremoteplayback
の3つの値のうち1つ以上を取ります。 HTMLMediaElement.crossOrigin
- このメディア要素の CORS 設定 を
DOMString
で参照できます。 HTMLMediaElement.currentSrc
読取専用- 選択されたメディアリソースの絶対 URL を
DOMString
で返します。 HTMLMediaElement.currentTime
- 現在の再生時間を
double
で返します。値を代入することで、シークを行えます。 HTMLMediaElement.defaultMuted
- 標準状態で音声がミュートされているか、いないかを表す、HTML の
muted
属性をBoolean
で参照できます。 HTMLMediaElement.defaultPlaybackRate
- 標準の再生レートを
double
で返します。 HTMLMediaElement.disableRemotePlayback
- リモート再生ができるかどうかを
Boolean
で取得できます。メディア要素にリモート再生UIを許可するかどうかを返します。 HTMLMediaElement.duration
読取専用- メディアの長さを秒数で表した数値を
double
で取得できます。メディアデータがない場合は、0 を返します。 HTMLMediaElement.ended
読取専用- 再生が終了しているか、いないかを
Boolean
で取得できます。 HTMLMediaElement.error
読取専用- 一番最後に起きたエラーを
MediaError
オブジェクトとして返します。エラーが起きていない場合は null を返します。 HTMLMediaElement.loop
- 繰り返し再生を有効、無効を表す HTML の
loop
をBoolean
として参照できます。 HTMLMediaElement.mediaGroup
- Is a
DOMString
that reflects themediagroup
HTML attribute, which indicates the name of the group of elements it belongs to. A group of media elements shares a commonMediaController
. HTMLMediaElement.mediaKeys
読取専用- Returns a
MediaKeys
object ornull
. MediaKeys is a set of keys that an associated HTMLMediaElement can use for decryption of media data during playback. HTMLMediaElement.mozAudioCaptured
読取専用- Returns a
Boolean
. Related to audio stream capture. HTMLMediaElement.mozFragmentEnd
- Is a
double
that provides access to the fragment end time if the media element has a fragment URI forcurrentSrc
, otherwise it is equal to the media duration. HTMLMediaElement.mozFrameBufferLength
-
Is a
unsigned long
that indicates the number of samples that will be returned in the framebuffer of eachMozAudioAvailable
event. This number is a total for all channels, and by default is set to be the number of channels * 1024 (e.g., 2 channels * 1024 samples = 2048 total).The
mozFrameBufferLength
property can be set to a new value for lower latency, larger amounts of data, etc. The size given must be a number between 512 and 16384. Using any other size results in an exception being thrown. The best time to set a new length is after the loadedmetadata event fires, when the audio info is known, but before the audio has started orMozAudioAvailable
events have begun firing. HTMLMediaElement.mozSampleRate
読取専用- Returns a
double
representing the number of samples per second that will be played. For example, 44100 samples per second is the sample rate used by CD audio. HTMLMediaElement.muted
- Is a
Boolean
that determines whether audio is muted.true
if the audio is muted andfalse
otherwise. HTMLMediaElement.networkState
読取専用- Returns a
unsigned short
(enumeration) indicating the current state of fetching the media over the network. HTMLMediaElement.paused
読取専用- Returns a
Boolean
that indicates whether the media element is paused. HTMLMediaElement.playbackRate
- Is a
double
that indicates the rate at which the media is being played back. HTMLMediaElement.played
読取専用- Returns a
TimeRanges
object that contains the ranges of the media source that the browser has played, if any. HTMLMediaElement.preload
- Is a
DOMString
that reflects thepreload
HTML attribute, indicating what data should be preloaded, if any. Possible values are:none
,metadata
,auto
. HTMLMediaElement.preservesPitch
- Is a
Boolean
that determines if the pitch of the sound will be preserved. If set tofalse
, the pitch will adjust to the speed of the audio. This is implemented with prefixes in Firefox (mozPreservesPitch
) and WebKit (webkitPreservesPitch
). HTMLMediaElement.readyState
読取専用- Returns a
unsigned short
(enumeration) indicating the readiness state of the media. HTMLMediaElement.seekable
読取専用- Returns a
TimeRanges
object that contains the time ranges that the user is able to seek to, if any. HTMLMediaElement.seeking
読取専用- Returns a
Boolean
that indicates whether the media is in the process of seeking to a new position. HTMLMediaElement.sinkId
読取専用- Returns a
DOMString
that is the unique ID of the audio device delivering output, or an empty string if it is using the user agent default. This ID should be one of theMediaDeviceInfo.deviceid
values returned fromMediaDevices.enumerateDevices()
,id-multimedia
, orid-communications
. HTMLMediaElement.src
- Is a
DOMString
that reflects thesrc
HTML attribute, which contains the URL of a media resource to use. HTMLMediaElement.srcObject
- Is a
MediaStream
representing the media to play or that has played in the currentHTMLMediaElement
, ornull
if not assigned. HTMLMediaElement.textTracks
読取専用- Returns the list of
TextTrack
objects contained in the element. HTMLMediaElement.videoTracks
読取専用- 要素の持つ
VideoTrack
オブジェクトのリストを参照できます。Gecko は 1 トラックの再生のみをサポートします。また複数トラックのメタデータ解析は、 Ogg フォーマットの場合にのみ有効です。
HTMLMediaElement.volume
- 音量を
double
で取得できます。この値は 0.0 (無音) 以上、1.0 (最大) 以下でなくてはなりません。
イベントハンドラー
HTMLMediaElement.onencrypted
- メディアが暗号化されている場合に呼ばれる
EventHandler
を設定できます。 HTMLMediaElement.onwaitingforkey
- Sets the
EventHandler
called when playback is blocked while waiting for an encryption key.
廃止された属性
These attributes are obsolete and should not be used, even if a browser still supports them.
HTMLMediaElement.initialTime
読取専用double
で、初期再生位置を示す値を秒単位で返します。HTMLMediaElement.mozChannels
読取専用- Returns a
double
representing the number of channels in the audio resource (e.g.,2
for stereo).
廃止されたイベントハンドラー
HTMLMediaElement.onmozinterruptbegin
- オーディオチャンネルマネージャによってメディア要素が割り込まれたときに呼び出される
EventHandler
を設定します。これは Firefox 固有のもので、 Firefox OS のために実装されていましたが、 Firefox 55 で削除されました。 HTMLMediaElement.onmozinterruptend
- 割り込みが完了したときに呼び出される
EventHandler
を設定します。これは Firefox 固有のもので、 Firefox OS のために実装されていましたが、 Firefox 55 で削除されました。
メソッド
このインターフェイスは祖先である HTMLElement
, Element
, Node
, EventTarget
のメソッドを継承しています。
HTMLMediaElement.addTextTrack()
- 字幕向けトラックのような、テキストトラックを追加します。
HTMLMediaElement.captureStream()
- Returns
MediaStream
, captures a stream of the media content. HTMLMediaElement.canPlayType()
- メディアタイプが再生可能かどうかを判定します。
HTMLMediaElement.fastSeek()
- 指定された時間へシークします。
HTMLMediaElement.load()
- メディア要素をリセットし、メディアリソースをリスタートします。処理されなかったイベントは破棄されます。メディアデータがダウンロードされる量は
preload
属性の値に影響されます。src
属性の値、もしくはsource
要素内の要素を削除した際のリソース解放、もしくはsource
の子要素が動的に変更される場合の再スキャンのために利用します。それ以外の場合に呼びだす必要はありません。 HTMLMediaElement.mozCaptureStream()
- [enter description]
HTMLMediaElement.mozCaptureStreamUntilEnded()
- [enter description]
HTMLMediaElement.mozGetMetadata()
- 再生中のメディアデータに対するメタデータを
Object
として返します。呼び出すたびに、オブジェクトのコピーが新しく作られます。このメソッドを呼び出すには、loadedmetadata イベント発火している必要があります。 HTMLMediaElement.pause()
- 再生を一時停止します。
HTMLMediaElement.play()
- 再生を開始します。
HTMLMediaElement.seekToNextFrame()
- Seeks to the next frame in the media. This non-standard, experimental method makes it possible to manually drive reading and rendering of media at a custom speed, or to move through the media frame-by-frame to perform filtering or other operations.
HTMLMediaElement.setMediaKeys()
- 再生に利用する
MediaKeys
を指定します。Promise
オブジェクトを返します。 HTMLMediaElement.setSinkId()
- 音声出力をレンダリングするデバイスの ID を指定できます。指定はアプリケーションからの利用が許されている場合に有効です。なお返り値は
Promise
オブジェクトとなっています。
廃止されたメソッド
These methods are obsolete and should not be used, even if a browser still supports them.
HTMLMediaElement.mozLoadFrom()
- このメソッドは Mozilla の独自実装で、他のメディア要素からデータをロードします。通常のリソース選択のアルゴリズムではなく、他の要素の
currentSrc
を選ぶ点以外は、load()
メソッドと同じように振る舞います。これは他の要素がキャッシュし、バッファしているデータを利用することにより最適化を図るためです。実際に、2 つの要素が同じダウンロードデータを利用する場合、どちらか一方のダウンロードが終われば、他方でもそのデータを利用できるようになります。
イベント
Inherits methods from its parent, HTMLElement
, defined in the GlobalEventHandlers
mixin. Listen to these events using addEventListener()
or by assigning an event listener to the oneventname
property of this interface.
abort
- Fired when the resource was not fully loaded, but not as the result of an error.
canplay
- Fired when the user agent can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content
canplaythrough
- Fired when the user agent can play the media, and estimates that enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
durationchange
- Fired when the duration attribute has been updated.
emptied
- Fired when the media has become empty; for example, when the media has already been loaded (or partially loaded), and the
HTMLMediaElement.load()
method is called to reload it. ended
- Fired when playback stops when end of the media (<audio> or <video>) is reached or because no further data is available.
error
- Fired when the resource could not be loaded due to an error.
loadeddata
- Fired when the first frame of the media has finished loading.
loadedmetadata
- Fired when the metadata has been loaded
loadstart
- Fired when the browser has started to load a resource.
pause
- Fired when a request to pause play is handled and the activity has entered its paused state, most commonly occurring when the media's
HTMLMediaElement.pause()
method is called. play
- Fired when when the
paused
property is changed fromtrue
tofalse
, as a result of theHTMLMediaElement.play()
method, or theautoplay
attribute playing
- Fired when playback is ready to start after having been paused or delayed due to lack of data
progress
- Fired periodically as the browser loads a resource.
ratechange
- Fired when the playback rate has changed.
seeked
- Fired when a seek operation completes
seeking
- Fired when a seek operation begins
stalled
- Fired when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
suspend
- Fired when the media data loading has been suspended.
timeupdate
- Fired when the time indicated by the currentTime attribute has been updated
volumechange
- Fired when the volume has changed.
waiting
- Fired when playback has stopped because of a temporary lack of data
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
Media Capture and Streams HTMLMediaElement の定義 |
勧告候補 | Adds sinkId and setSinkId() , and captureStream() . |
Encrypted Media Extensions Encrypted Media Extensions の定義 |
勧告 | Adds MediaKeys , MediaEncryptedEvent , setMediaKeys , onencrypted , and onwaitingforkey . |
HTML Living Standard HTMLMediaElement の定義 |
現行の標準 | HTML5 からの変更なし |
HTML5 HTMLMediaElement の定義 |
勧告 | 初回定義 |
ブラウザーの対応
BCD tables only load in the browser
関連情報
- 参考文献
<video>
および<audio>
- このインタフェースを継承している
HTMLVideoElement
とHTMLAudioElement
- 記事