HTML5 MULTIMEDIA PART2 CHAPTER 26
HTML Video
<video>
element is used to show a video on a web page.
The HTML <video> Element
To show a video in HTML, use the <video>
element:
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
How it Works
The controls
attribute adds video controls, like play, pause, and volume.
It is a good idea to always include width
and height
attributes. If height and width are not set, the page might flicker while the video loads.
The <source>
element allows you to specify alternative video files which the browser may choose from. The browser will use the first recognized format.
The text between the <video>
and </video>
tags will only be displayed in browsers that do not support the <video>
element.
HTML <video> Auto play
To start a video automatically use the autoplay
attribute
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" autoplay>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<p><b>Note:</b> The autoplay attribute does not work on some mobile devices.</p>
</body>
</html>
The autoplay attribute does not work in mobile devices like iPad and iPhone.
HTML Video - Methods, Properties, and Events
HTML defines DOM methods, properties, and events for the <video>
element.
This allows you to load, play, and pause videos, as well as setting duration and volume.
There are also DOM events that can notify you when a video begins to play, is paused, etc.
Example: Using JavaScript
HTML Audio
<audio>
element is used to play an audio file on a web pageThe HTML <audio> Element
To play an audio file in HTML, use the <audio>
element
<!DOCTYPE html>
<html>
<body>
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
HTML Audio - How It Works
The controls
attribute adds audio controls, like play, pause, and volume.
The <source>
element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format.
The text between the <audio>
and </audio>
tags will only be displayed in browsers that do not support the <audio>
element.
HTML Audio - Methods, Properties, and Events
HTML defines DOM methods, properties, and events for the <audio>
element.
This allows you to load, play, and pause audios, as well as set duration and volume.
There are also DOM events that can notify you when an audio begins to play, is paused, etc.
HTML Audio - Media Types
File Format | Media Type |
---|---|
MP3 | audio/mpeg |
OGG | audio/ogg |
WAV | audio/wav |
HTML Plug-ins
Plug-ins
Plug-ins were designed to be used for many different purposes:
- To run Java applets
- To run Microsoft ActiveX controls
- To display Flash movies
- To display maps
- To scan for viruses
- To verify a bank id
The <object> Element
The <object>
element is supported by all browsers.
The <object>
element defines an embedded object within an HTML document.
It was designed to embed plug-ins (like Java applets, PDF readers, and Flash Players) in web pages, but can also be used to include HTML in HTML:
<object width="100%" height="500px" data="snippet.html"></object>
The <embed> Element
The <embed>
element is supported in all major browsers.
The <embed>
element also defines an embedded object within an HTML document.
Web browsers have supported the <embed> element for a long time. However, it has not been a part of the HTML specification before HTML5.
<embed src="audi.jpeg">
HTML YouTube Videos
Struggling with Video Formats?
Earlier in this tutorial, you have seen that you might have to convert your videos to different formats to make them play in all browsers.
Converting videos to different formats can be difficult and time-consuming.
An easier solution is to let YouTube play the videos in your web page.
YouTube Video Id
YouTube will display an id (like tgbNymZ7vqY), when you save (or play) a video.
You can use this id, and refer to your video in the HTML code.
Playing a YouTube Video in HTML
To play your video on a web page, do the following:
- Upload the video to YouTube
- Take a note of the video id
- Define an <iframe> element in your web page
- Let the src attribute point to the video URL
- Use the width and height attributes to specify the dimension of the player
- Add any other parameters to the URL (see below)
YouTube Autoplay
You can have your video start playing automatically when a user visits that page by adding a simple parameter to your YouTube URL.
Note: Take careful consideration when deciding to autoplay your videos. Automatically starting a video can annoy your visitor and end up causing more harm than good.
Value 0 (default): The video will not play automatically when the player loads.
Value 1: The video will play automatically when the player loads.
<!DOCTYPE html>
<html>
<body>
<iframe width="420" height="345" src="https://www.youtube.com/embed/tgbNymZ7vqY?autoplay=1">
</iframe>
</body>
</html>
YouTube Playlist
A comma separated list of videos to play (in addition to the original URL).
YouTube Loop
Value 0 (default): The video will play only once.
Value 1: The video will loop (forever).
<!DOCTYPE html>
<html>
<body>
<iframe width="420" height="345" src="https://www.youtube.com/embed/tgbNymZ7vqY?playlist=tgbNymZ7vqY&loop=1">
</iframe>
</body>
</html>
YouTube Controls
Value 0: Player controls does not display.
Value 1 (default): Player controls display.
<!DOCTYPE html>
<html>
<body>
<iframe width="420" height="345" src="https://www.youtube.com/embed/tgbNymZ7vqY?controls=0">
</iframe>
</body>
</html>
FILE DOWNLOADING LINK BELOW
Comments
Post a Comment