HTML5 HTML5 Audio and Video 3 — Questions and Answers
Question 1: What is the Web Audio API primarily used for?
- Processing and synthesizing audio in the browser with JavaScript (Correct answer)
- Playing HTML5 <audio> elements only
- Recording audio from the microphone
- Streaming audio from a server
Correct answer: Processing and synthesizing audio in the browser with JavaScript
The Web Audio API provides a powerful system for controlling, processing, and synthesizing audio using an audio graph of nodes.
Question 2: Which API is used to capture audio and video from a user's webcam and microphone?
- MediaDevices.getUserMedia() (Correct answer)
- navigator.getMedia()
- MediaStream.capture()
- Camera.access()
Correct answer: MediaDevices.getUserMedia()
The getUserMedia() method of the MediaDevices API prompts the user for permission and returns a MediaStream from the camera or microphone.
Question 3: What does the MediaRecorder API enable in HTML5?
- Recording audio/video streams directly in the browser (Correct answer)
- Playing back recorded media files
- Capturing canvas frames as video
- Streaming media to a remote server
Correct answer: Recording audio/video streams directly in the browser
The MediaRecorder API provides functionality to record MediaStream data, saving audio and video blobs that can be downloaded or processed.
Question 4: Which video codec is widely supported by HTML5 browsers and uses the .mp4 container?
- H.264 (AVC) (Correct answer)
- Theora
- VP8
- AV1
Correct answer: H.264 (AVC)
H.264 (AVC) in an MP4 container has the broadest HTML5 browser support across desktop and mobile platforms.
Question 5: What event fires on an HTML5 media element when playback has reached the end?
- ended (Correct answer)
- complete
- finish
- stop
Correct answer: ended
The 'ended' event is fired when playback or streaming has stopped because the end of the media was reached.
Question 6: What does the 'poster' attribute on an HTML5 <video> element specify?
- An image to display before the video plays (Correct answer)
- The video's thumbnail in search results
- A fallback audio track
- The video's aspect ratio
Correct answer: An image to display before the video plays
The poster attribute specifies the URL of an image to display as the video's placeholder before the user plays it.
What is the Web Audio API primarily used for?