HTML5 HTML5 Audio and Video 2 — Questions and Answers
Question 1: What does the 'loop' attribute on an HTML5 <audio> element do?
- Causes the audio to restart automatically when it finishes (Correct answer)
- Loops through available audio sources
- Plays the audio in reverse loop
- Creates a crossfade loop
Correct answer: Causes the audio to restart automatically when it finishes
The loop attribute causes the audio element to automatically restart playback from the beginning when the media reaches the end.
Question 2: Which JavaScript method plays an HTML5 media element?
- play() (Correct answer)
- start()
- run()
- begin()
Correct answer: play()
The play() method on HTMLMediaElement begins or resumes playback and returns a Promise in modern browsers.
Question 3: What does the 'muted' attribute on a <video> element do?
- Silences the audio track of the video (Correct answer)
- Disables the video track
- Prevents volume changes
- Hides the audio controls
Correct answer: Silences the audio track of the video
The muted attribute sets the default audio state to muted, which is often required by browsers before autoplay is allowed.
Question 4: Which property of an HTML5 media element reports the current playback position in seconds?
- currentTime (Correct answer)
- playbackTime
- position
- timeElapsed
Correct answer: currentTime
The currentTime property returns or sets the current playback position of the media in seconds.
Question 5: What does the 'preload' attribute on an HTML5 <video> element hint to the browser?
- How much media data to load before the user starts playing (Correct answer)
- Whether to autoplay the video
- The video codec to use
- Whether buffering is allowed
Correct answer: How much media data to load before the user starts playing
The preload attribute with values 'none', 'metadata', or 'auto' hints to the browser how much of the media to preload before the user presses play.
Question 6: Which HTML5 API gives JavaScript programmatic control over media playback, seeking, and volume?
- HTMLMediaElement API (Correct answer)
- Web Audio API
- MediaStream API
- Media Session API
Correct answer: HTMLMediaElement API
The HTMLMediaElement API provides properties and methods like play(), pause(), currentTime, and volume for controlling audio and video elements.
What does the 'loop' attribute on an HTML5 element do?