Java Reference
In-Depth Information
(continued)
propertY name
desCription
Indicates whether the media element has ended playback
ended
Reflects the
loop
HTML attribute. Indicates whether the media element should
start over when playback reaches the end
loop
Gets or sets whether the audio is muted
muted
Indicates whether the media is paused
paused
Gets or sets the playback rate. 1.0 is normal speed.
playbackRate
Gets or sets the
poster
HTML attribute
poster
Reflects the
preload
HTML element attribute
preload
Gets or sets the
src
HTML attribute
src
The audio volume. Valid values range from 0.0 (silent) to 1.0 (loudest).
volume
Like the methods from the previous section, these properties are defined by the HTML5
specification, but some browser makers also implement their own proprietary properties. Also like
the aforementioned methods, the majority of these properties are straightforward; their names do a
pretty good job of describing what they're used for.
For example, the aptly named
paused
property can tell you if the media is paused, like this:
if (video.paused) {
video.play();
} else {
video.pause();
}
It's important to know that the default state of any media is paused. The browser only plays media
when it's told to do so—either explicitly with the
play()
method or via the built‐in controls, or
implicitly with the
autoplay
property/HTML attribute.
You can use the
muted
property to not only tell you if the audio is muted, but to also mute the
audio. For example:
if (video.muted) {
video.muted = false;
} else {
video.muted = true;
}
Or to write it in a more simplified manner:
video.muted = !video.muted;