Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,005 --> 00:00:02,001
- Earlier, we talked about how to put
2
00:00:02,001 --> 00:00:03,006
an image on a webpage.
3
00:00:03,006 --> 00:00:04,009
Images aren't the only kind of media
4
00:00:04,009 --> 00:00:06,006
you can put on a site,
5
00:00:06,006 --> 00:00:08,007
audio and video files are supported
6
00:00:08,007 --> 00:00:10,004
by HTML as well.
7
00:00:10,004 --> 00:00:13,007
Let's first take a look at audio.
8
00:00:13,007 --> 00:00:15,008
We can use the audio element to put
9
00:00:15,008 --> 00:00:17,004
audio files on a webpage.
10
00:00:17,004 --> 00:00:19,009
The HTML is fairly simple and it can
11
00:00:19,009 --> 00:00:21,008
trigger the browser to create an entire
12
00:00:21,008 --> 00:00:24,008
audio play or interface for us.
13
00:00:24,008 --> 00:00:26,007
The structure of the audio element
14
00:00:26,007 --> 00:00:28,007
is similar to the image element
15
00:00:28,007 --> 00:00:30,006
with a few differences.
16
00:00:30,006 --> 00:00:33,005
Unlike image, the audio element has both
17
00:00:33,005 --> 00:00:36,001
an opening and a closing tag.
18
00:00:36,001 --> 00:00:38,003
It's more modern and having both
19
00:00:38,003 --> 00:00:39,009
an opening and closing tag gives it
20
00:00:39,009 --> 00:00:41,008
more power and flexibility.
21
00:00:41,008 --> 00:00:43,007
Now just like the image element,
22
00:00:43,007 --> 00:00:46,001
we use a source attribute to provide
23
00:00:46,001 --> 00:00:47,006
the URL to the file.
24
00:00:47,006 --> 00:00:50,007
In this case, an audio file.
25
00:00:50,007 --> 00:00:52,006
There's more than one audio file format
26
00:00:52,006 --> 00:00:54,006
we can use and I'll talk about which formats
27
00:00:54,006 --> 00:00:56,001
are best in a few minutes.
28
00:00:56,001 --> 00:00:59,004
For now let's just link to this MP3 file.
29
00:00:59,004 --> 00:01:01,007
So what does this do?
30
00:01:01,007 --> 00:01:05,000
Well, actually nothing very useful yet.
31
00:01:05,000 --> 00:01:07,003
We need to tell the browser that yes,
32
00:01:07,003 --> 00:01:09,003
in fact we do want the browser to
33
00:01:09,003 --> 00:01:10,008
provide some controls.
34
00:01:10,008 --> 00:01:11,006
A play button,
35
00:01:11,006 --> 00:01:12,005
a timeline,
36
00:01:12,005 --> 00:01:13,009
a volume control.
37
00:01:13,009 --> 00:01:15,006
Using the controls that are built
38
00:01:15,006 --> 00:01:17,000
into the browser is optional.
39
00:01:17,000 --> 00:01:19,005
We could instead make our own custom controls
40
00:01:19,005 --> 00:01:23,005
using JavaScript and the HTML media element API.
41
00:01:23,005 --> 00:01:25,002
But let's not do that.
42
00:01:25,002 --> 00:01:28,009
Let's add the word controls as an attribute.
43
00:01:28,009 --> 00:01:30,009
If controls is there,
44
00:01:30,009 --> 00:01:32,002
it means true,
45
00:01:32,002 --> 00:01:34,006
yes please do include them.
46
00:01:34,006 --> 00:01:36,002
Boom!
47
00:01:36,002 --> 00:01:38,005
Now we cave an audio player on the page.
48
00:01:38,005 --> 00:01:39,003
We can play,
49
00:01:39,003 --> 00:01:40,002
pause,
50
00:01:40,002 --> 00:01:41,000
and change the volume,
51
00:01:41,000 --> 00:01:42,000
see the time code,
52
00:01:42,000 --> 00:01:44,000
jump around in the timeline.
53
00:01:44,000 --> 00:01:46,000
The audio element is a good example of
54
00:01:46,000 --> 00:01:48,008
the power of HTML to provide a bunch of
55
00:01:48,008 --> 00:01:50,006
functionality that maybe we just don't
56
00:01:50,006 --> 00:01:53,001
want to bother to build ourselves.
57
00:01:53,001 --> 00:01:55,006
We can use what the browser provides.
58
00:01:55,006 --> 00:01:57,007
There are several other attributes that
59
00:01:57,007 --> 00:01:59,007
we can use with audio.
60
00:01:59,007 --> 00:02:01,007
Loop will make the file loop.
61
00:02:01,007 --> 00:02:03,002
When it gets to the end,
62
00:02:03,002 --> 00:02:05,006
it starts playing from the beginning again.
63
00:02:05,006 --> 00:02:07,006
Autoplay will cause the audio to be
64
00:02:07,006 --> 00:02:10,000
played automatically as soon as the page loads,
65
00:02:10,000 --> 00:02:11,008
at least in some browsers.
66
00:02:11,008 --> 00:02:13,004
Now be careful with autoplay.
67
00:02:13,004 --> 00:02:15,008
Most people actually hate it when
68
00:02:15,008 --> 00:02:17,006
the audio starts playing automatically
69
00:02:17,006 --> 00:02:18,007
when they land on a webpage,
70
00:02:18,007 --> 00:02:22,000
so maybe don't use that one.
71
00:02:22,000 --> 00:02:26,000
So why do we have both an opening and closing tag?
72
00:02:26,000 --> 00:02:28,006
That's so that we can use the source element
73
00:02:28,006 --> 00:02:31,004
to specify more than one audio file,
74
00:02:31,004 --> 00:02:34,007
much like we could with the picture element.
75
00:02:34,007 --> 00:02:36,007
Perhaps you want to use a new file format
76
00:02:36,007 --> 00:02:38,003
that's not supported in every browser
77
00:02:38,003 --> 00:02:41,002
while providing a fallback for the older browsers.
78
00:02:41,002 --> 00:02:43,006
Let's remove the source attribute from
79
00:02:43,006 --> 00:02:46,001
the audio element and instead put
80
00:02:46,001 --> 00:02:48,000
it on a source element.
81
00:02:48,000 --> 00:02:50,002
This will do the exact same thing as our previous
82
00:02:50,002 --> 00:02:52,006
example but now we can add additional
83
00:02:52,006 --> 00:02:54,004
source elements with alternative
84
00:02:54,004 --> 00:02:57,002
audio file formats.
85
00:02:57,002 --> 00:03:00,004
MP3s are supported in most modern browsers today.
86
00:03:00,004 --> 00:03:03,005
OGG is another file format that had some
87
00:03:03,005 --> 00:03:06,003
advantages but it never became very popular.
88
00:03:06,003 --> 00:03:08,009
It seems that a new format may come out soon,
89
00:03:08,009 --> 00:03:12,003
the cousin to the AV1 video file format.
90
00:03:12,003 --> 00:03:14,008
But it's not quite here yet.
91
00:03:14,008 --> 00:03:17,007
So I don't really have a second audio
92
00:03:17,007 --> 00:03:20,005
file format to recommend using at the moment.
93
00:03:20,005 --> 00:03:22,002
But I want to show you the syntax for
94
00:03:22,002 --> 00:03:24,004
supporting multiple formats since
95
00:03:24,004 --> 00:03:26,008
it was important for a while and it's likely
96
00:03:26,008 --> 00:03:28,006
to be very useful again sometime
97
00:03:28,006 --> 00:03:30,002
in the near future.
98
00:03:30,002 --> 00:03:32,007
We can make multiple files and list them
99
00:03:32,007 --> 00:03:34,009
in separate source elements.
100
00:03:34,009 --> 00:03:37,006
The browser will use the first file that
101
00:03:37,006 --> 00:03:39,007
it understands in the list.
102
00:03:39,007 --> 00:03:41,006
This is how the syntax works.
103
00:03:41,006 --> 00:03:44,008
You can also provide some fallback text in here
104
00:03:44,008 --> 00:03:47,000
that will only be displayed if the audio element
105
00:03:47,000 --> 00:03:49,008
is not understood by the browser at all.
106
00:03:49,008 --> 00:03:51,006
This is a good example of the resilience
107
00:03:51,006 --> 00:03:54,003
built into HTML where you can write
108
00:03:54,003 --> 00:03:57,004
one set of code and provide a wide
109
00:03:57,004 --> 00:03:59,009
variety or browsers what each of them need
110
00:03:59,009 --> 00:04:03,002
to give some kind of experience to their users.
111
00:04:03,002 --> 00:04:05,005
The audio element is a great way to get
112
00:04:05,005 --> 00:04:08,006
an audio file along with a player
113
00:04:08,006 --> 00:04:11,000
onto a webpage.
7669
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.