Video, Audio & Media in HTML | Sigma Web Development Course - Tutorial #10

CodeWithHarry
5 Oct 202314:47

Summary

TLDRThis tutorial video delves into the utilization of audio, video, and media elements in HTML. It demonstrates embedding videos with attributes like autoplay, muted, and controls, as well as adjusting dimensions. The video also covers the audio tag, showcasing controls, autoplay, loop, and muted functionalities. Additionally, it explains the preload attribute's impact on media loading and introduces SVG for creating vector images and iframes for embedding websites. The presenter concludes with a quick quiz, encouraging viewers to create a categorized media website using these elements.

Takeaways

  • πŸ“Ή HTML supports embedding media elements like audio and video directly within the webpage.
  • πŸ” The 'autoplay' attribute allows a video to start playing as soon as the page loads.
  • πŸ”‡ The 'muted' attribute can be used to ensure the video starts without sound, which is useful for instructional videos.
  • β­• The 'loop' attribute makes the video restart once it reaches the end.
  • πŸŽ₯ The 'controls' attribute adds playback controls like play, pause, and volume adjustment to the video element.
  • 🌐 The 'src' attribute in video and audio tags specifies the source file, which can be a local file or an external URL.
  • πŸ–ΌοΈ The 'poster' attribute in the video tag can display an image before the video starts playing, similar to a thumbnail.
  • πŸ”Š The 'preload' attribute in audio tags determines how much of the audio file is loaded when the page loads, with options like 'none', 'metadata', or 'auto'.
  • 🎢 The audio tag in HTML is used to embed sound files and can be controlled similarly to video with attributes like 'autoplay', 'loop', and 'muted'.
  • πŸ–ΌοΈ SVG (Scalable Vector Graphics) can be used in HTML to create and display high-quality, scalable images.
  • πŸ”— The 'iframe' element allows embedding another webpage within the current page, which can be useful for including content like YouTube videos.

Q & A

  • What are the main topics covered in the video?

    -The video covers how to use audio, video, and media elements in HTML, including autoplay, muting, video controls, and using attributes like loop, muted, and poster.

  • How do you add a video in HTML?

    -To add a video in HTML, use the <video> tag with the src attribute pointing to the video file, and optional attributes like controls, autoplay, loop, and muted.

  • What is the purpose of the 'controls' attribute in the <video> tag?

    -The 'controls' attribute adds video controls such as play, pause, volume, fullscreen, and download options to the video.

  • How can you autoplay a video when the page loads?

    -You can autoplay a video by adding the 'autoplay' attribute to the <video> tag.

  • What does the 'loop' attribute do in the <video> tag?

    -The 'loop' attribute makes the video start over again automatically after it finishes playing.

  • How can you mute a video in HTML?

    -You can mute a video by adding the 'muted' attribute to the <video> tag.

  • What is the 'poster' attribute used for in the <video> tag?

    -The 'poster' attribute is used to specify an image to be shown while the video is downloading, or until the user hits the play button.

  • How do you add audio in HTML?

    -To add audio in HTML, use the <audio> tag with the src attribute pointing to the audio file, and optional attributes like controls, autoplay, loop, and muted.

  • What is the 'preload' attribute in the <audio> tag?

    -The 'preload' attribute specifies if and how the author thinks the audio should be loaded when the page loads. It can have values 'none', 'metadata', or 'auto'.

  • What is an iframe and how is it used?

    -An iframe is an HTML element that allows you to embed another HTML page within the current page. It is used to embed content like another website or a YouTube video.

  • What are SVG files and how are they used in HTML?

    -SVG (Scalable Vector Graphics) files are used to define vector-based graphics for the web. They can be embedded directly in HTML using the <svg> tag or linked as an external file using the <img> tag.

  • How can you ensure an SVG file displays correctly in a browser?

    -To ensure an SVG file displays correctly in a browser, include the XML namespace declaration at the beginning of the SVG file.

Outlines

00:00

πŸ“Ή HTML5 Media Elements: Video and Audio Basics

This paragraph introduces the use of HTML5 media elements, focusing on video and audio tags. It explains how to embed videos in HTML, control video playback features such as autoplay, muted, and controls, and adjust video dimensions. The speaker also discusses the importance of the 'src' attribute for video files, whether they are local or from an external source. Additionally, it touches on the use of the 'poster' attribute to display a thumbnail before video playback.

05:02

πŸ”Š Deep Dive into Audio Attributes and Preload Options

The second paragraph delves deeper into the audio element in HTML, demonstrating how to embed and control audio playback with attributes like 'controls', 'autoplay', 'loop', and 'muted'. It highlights the peculiarities of the 'preload' attribute, explaining its different values and their impact on how audio files are loaded by the browser. The speaker also encourages viewers to share the playlist and engage with the content by liking and starring the repository to support the creation of free educational resources.

10:04

πŸ–ΌοΈ Exploring SVG Integration and Iframe Embedding

The final paragraph covers additional media-related HTML elements, starting with SVG for creating high-quality vector images that can be used inline like the 'img' tag. It addresses common issues with displaying SVG files in browsers and the necessity of including a namespace declaration. The paragraph also explains how to use 'iframe' tags to embed external websites or YouTube videos, providing examples of how to adjust iframe dimensions and start videos at specific timestamps. The speaker concludes with a quick quiz challenge for viewers to create a categorized media website using the discussed elements and encourages interaction through comments and GitHub.

Mindmap

Keywords

πŸ’‘HTML

HTML, or HyperText Markup Language, is the standard language used to create and design web pages. It forms the backbone of the internet by providing the structure and content of a webpage. In the video, HTML is used to embed various media elements such as video, audio, and SVG, showcasing how these elements can be integrated into a webpage to enhance user experience.

πŸ’‘Video Element

The video element is a key concept in the script, referring to the HTML tag used to embed video content into a webpage. The script explains how to use attributes like 'src', 'controls', 'autoplay', 'loop', and 'muted' to customize the video playback experience. For example, the 'autoplay' attribute allows the video to start playing as soon as the page loads, while 'muted' ensures the video plays without sound by default.

πŸ’‘Audio Element

Similar to the video element, the audio element is an HTML tag that allows audio content to be embedded into a webpage. The script discusses attributes such as 'src', 'controls', 'autoplay', 'loop', and 'muted' for the audio element. It demonstrates how to control the audio playback, including automatically playing the audio and looping it to repeat the audio content.

πŸ’‘Media Controls

Media controls refer to the set of interactive buttons and sliders provided by the browser for controlling media playback, such as play, pause, and volume. The script mentions that these controls are automatically included when the 'controls' attribute is added to the video or audio element, giving users the ability to interact with the media content on the webpage.

πŸ’‘Autoplay

The 'autoplay' attribute, when added to a media element, instructs the browser to begin playing the media as soon as the webpage is loaded. In the script, the concept of autoplay is explained in the context of both video and audio elements, emphasizing its role in automatically initiating media playback without user interaction.

πŸ’‘Muted

The 'muted' attribute is used to silence the audio output of a media element by default. The script explains how to apply the 'muted' attribute to both video and audio elements, which can be useful for avoiding unwanted noise or for situations where the audio is not essential to the content.

πŸ’‘Poster

The 'poster' attribute is associated with the video element and specifies an image to display as a placeholder before the video is played. In the script, the poster attribute is used to show a thumbnail image that represents the video content, which can entice users to play the video or provide context if the video does not autoplay.

πŸ’‘SVG

SVG stands for Scalable Vector Graphics, which is a format for creating high-quality, resolution-independent images that can be scaled to any size without loss of quality. The script discusses SVG as a media element that can be embedded into HTML pages using the 'img' tag or by including the SVG code directly in the HTML document.

πŸ’‘Iframe

An iframe, or inline frame, is an HTML element that allows one webpage to be embedded within another. The script demonstrates how to use the iframe element to include external websites or content, such as YouTube videos, within a webpage. This can be used for displaying third-party content or creating a more integrated browsing experience.

πŸ’‘Preload Attribute

The 'preload' attribute in HTML media elements provides a way to suggest how much of the media resource to preload. The script explains the different values this attribute can have, such as 'none', 'metadata', and 'auto', which dictate whether the browser should preload the media file, its metadata, or the entire file for faster playback.

Highlights

Introduction to how audio, video, and media elements are used in HTML.

Explanation of embedding videos in HTML and controlling autoplay, muting, and enabling/disabling video controls.

Demonstration of adding a video tag with src attribute in an HTML file.

Adjusting video dimensions using width and height attributes without needing to specify 'px'.

Using the controls attribute to enable browser-provided video controls like play, pause, and volume.

Details on the SRC attribute allowing video files from external URLs or servers.

Autoplay attribute to automatically start video playback when the page loads.

Loop attribute to repeat the video playback.

Muted attribute to mute the video by default.

Poster attribute to display an image before the video plays, functioning like a thumbnail.

Introduction to audio tags and their usage in HTML with SRC attribute.

Controls attribute for audio tags to enable play, pause, and volume adjustments.

Autoplay and loop attributes for audio, allowing automatic playback and repetition.

Muted attribute for audio to mute it by default and provide user control to unmute.

Preload attribute explained with different values: none, metadata, and auto.

SVG introduction as a format for creating high-graphics vector images.

SVG usage similar to the img tag and the importance of namespace declaration for display.

Iframe explanation for embedding another website within your own.

Using iframes to embed YouTube videos with specific start times.

Quick quiz challenge to create a website with categorized videos and audios using HTML media elements and iframes.

Encouragement to share the playlist, like the video, and participate in the quiz with 'sigma batch op' in the comments.

Transcripts

play00:00

In today's video, we will learn how audio, video and media elements are used in HTML.

play00:05

We saw in our very first video that we can embed videos in HTML.

play00:10

Today I will tell you how the video is auto-played,

play00:13

how to keep a muted video and how you can enable and disable the video controls.

play00:19

Along with that, we will also see very closely about audio,

play00:22

how media can be shown in an overall page

play00:25

So do like this video

play00:27

And stay in this video

play00:28

Because the examples I have used for video tags are very good

play00:32

Let's go to the video screen

play00:34

Let's roll the intro

play00:35

Intro

play00:44

Friends, this time I have made a folder named video10

play00:47

and I will not waste your time by opening open with code by right clicking on shift

play00:51

In fact, I will make it in index.html

play00:54

And the topic of today's video is video

play00:57

How to play a video, how to put a video in an html file

play01:02

How to put audio, how to put media

play01:06

so adding video is very straight forward

play01:08

I will copy it here, which is our video tag

play01:12

it has an src attribute and it has some other attributes

play01:15

which I will discuss with you

play01:17

but first of all I want to tell you here

play01:19

that video src is equal to you will write here

play01:21

so if you have video.mp4 then it will play

play01:24

I have video.mp4 so let's see here

play01:27

I have put it here with ctrl

play01:28

and I will click here and preview it

play01:30

and you can see here that this video has come

play01:33

now this is a very big video

play01:35

so what can I do is I can give its width

play01:38

so I can say width is equal to 555 pixels

play01:41

and as soon as I do 555 pixels

play01:44

in fact I don't need to write px I will just, in fact, I don't need to write px, I'll just do 555.

play01:46

Like we don't need to write px in the image,

play01:49

we don't need to write px here either.

play01:51

So as soon as I did width is equal to 555,

play01:54

in fact, I do one thing, I do height is equal to 555

play01:57

so that it becomes smaller, in fact, I make it smaller,

play02:00

I do 255 and you see it came here, okay.

play02:03

Now I play it because I have taken control, I can set it to 255 and you see it came here. Now I play it because I have set the controls, I can play it.

play02:06

What did you say?

play02:07

America is a good road right now.

play02:08

What did you say?

play02:09

What's your name?

play02:10

Where have you been in the US?

play02:11

I have been to many places in the US.

play02:12

Tell me your name.

play02:13

Gopindra Jogi

play02:14

Ha ha ha ha ha

play02:15

So, you can play the video like this.

play02:18

Now here are some attributes of the video tag.

play02:20

It is very simple to use the video tag.

play02:22

You should have a video.

play02:23

You have given the path of the video.

play02:25

After that you have given the controls.

play02:26

So these controls will come to you.

play02:27

You can download it.

play02:29

You can do full screen.

play02:30

You can mute.

play02:31

You can do picture in picture.

play02:32

All this is automatically provided by your browser.

play02:35

But let me tell you about some attributes.

play02:36

The first attribute is SRC.

play02:37

So you know that put the video here.

play02:40

The name of the video file is SRC.

play02:42

This video file can also come from an external URL.

play02:45

If I have uploaded a video on Amazon S3 or somewhere else,

play02:49

then I can also put the URL of that video here.

play02:51

It is not necessary that the file is in your computer.

play02:53

It can also be on your server.

play02:54

It can also come from a third party.

play02:56

Now what does the control do?

play02:57

Adds video controls like play, pause and volume.

play03:00

Which we saw here in the video of Bhupendra Jogi.

play03:02

You are getting to see the controls here.

play03:05

Now what is this thing? The browser automatically sees what control ads will be in your video,

play03:11

what will not be there. Then see what will autoplay do? It will automatically play as soon as the page loads.

play03:15

Okay, so if I put autoplay here, you can see here that it is auto-play.

play03:26

So I will remove auto-play from here.

play03:28

And our next attribute

play03:30

is loop. Means once

play03:32

our video is played

play03:34

then it will loop.

play03:36

Like I will show you.

play03:38

Where did you see the market?

play03:40

So it started again.

play03:42

Once I finished it, it started again.

play03:44

So this loop works like this.

play03:47

The next attribute is muted, muted mutes the video.

play03:50

So if I write here muted, sometimes we want the video to be muted.

play03:53

In fact, when I add videos here on codewithhari.com

play03:57

and I demonstrate something like downloading VS code or something

play04:00

then I use the muted attribute.

play04:02

Because I don't want that when I record a video,

play04:04

if there is any background noise, you can hear it

play04:06

for example, I want to show you that this is the element

play04:08

so I will scroll and make a video

play04:10

I will highlight it like this, so I don't need audio in it

play04:12

so I mute it

play04:14

so you can use muted attribute in your websites

play04:17

then poster, poster is very important

play04:19

so I have an image here

play04:21

download.jpg

play04:23

if I write here poster is equal to and I, download.jpg If I write here, poster is equal to

play04:26

and I write download.jpg

play04:28

so you can see it will look like this

play04:30

this is how the poster looks like, if I play it

play04:32

the video will play, so in a way it's a thumbnail

play04:34

you have seen the thumbnail of a YouTube video

play04:36

it's exactly the same, this poster attribute

play04:38

so you can use all these attributes

play04:41

you know that width and height specifies the dimension of the video

play04:44

like I have added both width and height here you saw, so and height you know that specifies the dimension of the video like I have added width and height here

play04:46

you saw, so I hope you understood this thing

play04:50

now after this the thing I want to tell you is audio

play04:54

so this is for all the attributes of your video

play04:56

it is very straight forward, I want you to

play04:58

make a website which I am going to give you at the end of this video

play05:02

in quick quiz, so listen to the quick quiz

play05:04

infact I will put the heading here, quick quiz, okay?

play05:07

So that I don't forget.

play05:09

I will give this to you now.

play05:10

And this is going to be a very interesting quiz and everyone must solve it.

play05:13

But before that,

play05:16

as soon as you type audio, you get SRC here.

play05:18

And I have to put SRC in sachin.mp3.

play05:21

So as soon as I put it in sachin.mp3,

play05:23

you see here, I will reload it.

play05:27

And there is no audio here, which is strange coming here. I have to write controls here.

play05:32

So if I don't write controls, I won't see the audio.

play05:35

Now the audio is here. I can see the controls and set the volume.

play05:39

I play this audio.

play05:40

Sachin, what is in Sachin?

play05:42

Sachin is a fool.

play05:43

So this is our audio. If I mute it, it won't work. I can also increase it further. Sachin is what is in Sachin? He is a stupid Sachin So this is our audio, if I mute it

play05:46

then it won't work, I can increase it further

play05:48

He is a stupid Sachin

play05:50

So you have seen, this is Sachin.mp3 audio

play05:52

Now what we will do is

play05:54

we will see some attributes of this audio

play05:56

SRC you know that

play05:58

source of video file

play06:00

then you know controls

play06:02

play, pause or volume, which we have seen

play06:04

what will autoplay do? it will automatically play

play06:06

if i here

play06:08

auto play, it will play automatically

play06:10

ok

play06:12

so what will auto play do?

play06:14

it will play automatically

play06:16

after this next attribute

play06:18

is loop, what will loop do?

play06:20

it will repeat, if i want to loop

play06:22

it, so i auto play it and i loop it

play06:24

once it will repeat it, if I want to loop it, then I will auto play it and loop it Sachin, what is in Sachin?

play06:26

Sachin is a fool.

play06:27

Once.

play06:28

Sachin, what is in Sachin?

play06:29

Second time.

play06:30

Fool.

play06:31

So you saw that it was repeated, means it was played once, then it was played again.

play06:35

Because I had looped the audio, okay.

play06:37

So you saw this thing.

play06:38

Sachin.mp3, I looped it.

play06:40

Means it was played once, then it was played.

play06:42

Then it was played, okay.

play06:43

What is Sachin? Sachin, okay.

play06:44

She was repeating it again and again. Because this again, then it played again, ok what is Sachin, Sachin, ok, it was repeating again and again

play06:46

because this MP3 will play again and again

play06:49

so there are many cases of this that when you want this MP3 to repeat

play06:54

ok, so if you want your MP3 to repeat then you can use this

play06:58

now after this, what will mutate do, it will mute the audio

play07:02

and definitely you don't want your audio to be muted by default

play07:06

but sometimes we want that

play07:09

the audio is muted and we can tell the user

play07:12

that listen to this and unmute it

play07:15

we do this when we have multiple audios

play07:18

you want to show 5-6 audios at once, you can mute them

play07:21

the user can play and unmute and watch

play07:24

so you have the control, you can use it if you want

play07:28

so in total this is the thing, I hope you understood this thing

play07:32

you must have enjoyed, now preload, the most confusing attribute

play07:36

that's why I have explained it on codewithaddy.com

play07:38

that the preload attribute can have these values

play07:42

the first value can be none, this is the default value

play07:44

it indicates that the browser should not preload the audio at all

play07:47

preload means if you want the browser to fetch the data from the beginning then you will use the preload attribute

play07:54

otherwise you will not use the preload attribute, preload is equal to none, default value, preload is equal to metadata means

play08:01

that the browser will preload the information about the audio file, means it will preload the audio file

play08:07

And by auto, browser will preload the audio file

play08:11

So preload is equal to auto, so it will download and automatically load

play08:16

So that whenever user plays it, it will save the audio

play08:20

So this is the work of preload attribute

play08:22

And this is asked a lot in interviews, So you should know what is preload attribute.

play08:26

Before moving forward, I want you to share this playlist with your friends.

play08:30

Because I am seeing that the interest is declining a lot.

play08:32

As we are moving forward in the videos.

play08:34

My request to you is that you like this video.

play08:38

And along with that, as you are forking this repository,

play08:41

Keep starting it.

play08:43

Your star, your likes, all this will help me a lot to bring such free courses

play08:48

So this was about audio and video tags

play08:51

I have also told you all the attributes

play08:53

And you should definitely use it

play08:55

I will give you all the images so that you can try it out

play08:59

Now many people were asking if we can use replit

play09:03

See, I have not used replit

play09:06

But replit.com is an amazing website

play09:08

If you want to use it in your phone

play09:10

If you want to run html

play09:12

There is a replit app for ios

play09:14

There is also for android

play09:16

So you can try it out

play09:17

Many people are asking how to do recording in the phone

play09:19

But what I want now is vs code

play09:21

Which most of the people want to use

play09:24

Prefer So I thought why not make videos in VS code which most of the people prefer

play09:25

So I thought why not make videos in VS code

play09:28

But I personally use replit a lot

play09:31

Infact videos also comes in replit

play09:32

Next topic is SVG

play09:34

Related to media

play09:35

What is SVG?

play09:36

SVG is a format through which you can create images

play09:40

With high graphics

play09:43

So if you copy you can make high graphics vector images so if you copy you can make circle

play09:46

so svg is used exactly like

play09:49

how our img tag is used

play09:52

so if i put svg here

play09:55

so this svg will come here

play09:58

video, audio, svg are inline elements

play10:01

that's why we are seeing them in one line

play10:04

you have seen it here

play10:06

now what is here, you can save svg file separately

play10:10

you can save svg file separately, like if i write here

play10:12

img.svg and save svg content in it

play10:17

so if i write img here

play10:20

and i will write img.svg

play10:23

so you guys see here, I didn't get this image

play10:26

if I write alt here and write my svg image

play10:30

so you can see here that my svg image is like this

play10:33

but I didn't get to see svg

play10:34

why did this happen?

play10:36

this happened because the svg

play10:38

I write svg file in browser

play10:42

and whenever you want to see svg file in browser you will put a declaration above, I will write file in browser and svg file whenever you want to see it in browser

play10:46

you will put a declaration above it, I will show you

play10:49

so I have written svg file not showing

play10:52

so here is an answer of stack overflow

play10:55

which will tell you, so you have to write this

play10:58

xml something like this

play11:01

you have to add this, it is called namespace declaration

play11:04

so you have to add this It's called namespace declaration So you have to add this SVG

play11:06

And now you can see SVG here

play11:09

So this is very important

play11:11

And when you will make your own websites in future

play11:14

You will definitely get stuck in this problem

play11:16

I get stuck in this problem

play11:18

So I am telling you that I have already told you the problem you will get stuck in

play11:21

You didn't get the problem, I have already told you the problem and the solution

play11:24

Next topic is iframes

play11:26

Iframes is a very simple thing

play11:28

You can embed another website in your website

play11:32

Like if I want to embed this webpage

play11:35

I can use iframes like this

play11:38

I will copy this url

play11:42

I will paste it here

play11:44

And you can see that this website is completely embedded here

play11:47

in this small iFrame, okay?

play11:48

You definitely want to embed it in a big iFrame

play11:51

but if you want it to be embedded, then you can embed it like this

play11:54

I will do one thing, I will increase its height a little

play11:57

so width is equal to width is written

play11:59

width is equal to let's say 122

play12:01

height is equal to 444, okay?

play12:04

Assume, so see it came like this, okay, now definitely it was coming in this width,

play12:08

so it came in this line, but if I increase the width a little,

play12:11

let's say I increase the width, 322, okay,

play12:15

so see here, my website is completely embedded,

play12:18

are you seeing, so you can embed a website,

play12:21

another use case of iframe is YouTube video,

play12:23

if you want to share youtube video

play12:26

and click on embed

play12:28

it will give you iframe code

play12:30

and you can start it from here

play12:32

if you want to start at a particular time

play12:34

you can do that

play12:36

the point at which you will start and share

play12:38

that time will come here

play12:40

let me show you

play12:42

let's say I want to start from here

play12:44

let's say video starts from here so I will click on share

play12:47

after that I will click on embed

play12:49

I will start at 12.19

play12:51

and I will copy it

play12:52

there is a copy button

play12:53

and I will put it in my code

play12:55

so I will comment this iframe

play12:57

and I will put it in the iframe below

play12:59

I will wrap the word so that you can see the code properly

play13:03

so now what I will do is after pasting this I will show word wrap so that you can see the code properly. So now what I will do is after pasting this,

play13:06

I will show you the document.

play13:08

See this video is embedded here.

play13:11

So I hope you understood this thing.

play13:14

And this is all that happens in media html.

play13:17

Miscellaneous, you will get to see a lot of things in every topic.

play13:21

But pretty much that's all about media html.

play13:23

Audio, video, media is that much

play13:26

This is what you will use 95% of the times

play13:29

Now I will give you a quick quiz

play13:32

And your quick quiz is

play13:35

Create a website which shows videos of different categories

play13:38

And audios of different categories

play13:41

You can use YouTube videos in an iframe

play13:44

Using YouTube's embedding feature

play13:46

so what you have to do is you have to make a website

play13:50

in which you will get a lot of content, now you can use video audio tags and YouTube's

play13:55

share feature, the way I have embedded this YouTube video, you can do the same

play14:01

and make a very good website and show me, You can also give me a comment in the github.

play14:06

And you can also

play14:08

tell me the code.

play14:10

But do attempt this quiz.

play14:12

And do write sigma batch op in the comment section.

play14:14

Access this playlist.

play14:16

Like the video.

play14:18

And do write sigma batch op.

play14:20

That's all for this video.

play14:22

Thank you so much for watching this video.

play14:24

And I will see you next time.

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
HTML5Media ElementsWeb DevelopmentVideo TutorialAudio EmbeddingAutoplay VideosMuted AudioVideo ControlsSVG GraphicsIframe EmbedQuick Quiz