8. Multimedia
Since the arrival of the HTML5 version there are some interesting tags that offer multimedia content: audio and video. We can play music or a whole movie without going through other services (like Flash or Youtube); in a simple, free and operating-system-integrated way.
Audio
| Tag | <audio> |
|---|---|
| Description | Embed sound in a document. |
| Attributes | autoplay Starts the audio when the document is displayed.controls Shows controls so the user can manage playback.loop Specifies that the audio should play again when it ends. muted Specifies that the audio starts muted.src Path of the audio. |
| Type | Inline |
<audio
controls
src="t-rex.mp3"
>
<p>
Your browser does not support the audio format, click <a href="t-rex.mp3">here</a> to download it.
</p>
</audio>
If what we're looking for is to add a description we'll play with <figure> and <figcaption>.
<figure>
<figcaption>T-Rex:</figcaption>
<audio
controls
src="t-rex.mp3"
>
<p>
Your browser does not support the audio format, click <a href="t-rex.mp3">here</a> to download it.
</p>
</audio>
</figure>
Compatibility
The most used audio formats in web creation are:
mp3wavoggwebmaac
Each one has its own advantages and disadvantages, but what's important are the codecs and their compatibility. Not all browsers can play the same formats; some require licenses that (the browsers) don't want to pay for, or there are certain economic interests in not providing support. So we can't guarantee that it plays on all devices? As we saw in the images lesson, there's a tag that solves the problem for us: <source>.
In the following example I tell the browser to play the audio in case it's compatible with mp3; otherwise it would try with ogg.
<audio controls>
<source srcset="t-rex.mp3" type="audio/mp3">
<source srcset="t-rex.ogg" type="audio/ogg">
<p>
Your browser does not support the audio format, click <a href="t-rex.mp3">here</a> to download it.
</p>
</audio>
Video
If the goal is to include a video Youtube-style, in the catalog of tags we can find one that is an expert at the task.
| Tag | <video> |
|---|---|
| Description | Embed video in a document. |
| Attributes | autoplay Starts the audio when the document is displayed.controls Shows controls so the user can manage playback.loop Specifies that the video should play again when it ends. muted Specifies that the video starts muted.src Path of the audio.width: Width of the video.poster: Image that will be shown before playing. |
| Type | Inline |
<video controls src="te.mp4">
<p>
Your browser does not support the video format, click <a href="te.mp4">here</a> to download it.
</p>
</video>
To avoid problems with browsers we can add more sources, as we did in <audio>.
<video controls>
<source src="te.webm" type="video/webm">
<source src="te.mp4" type="video/mp4">
<p>
Your browser does not support the video format, click <a href="te.mp4">here</a> to download it.
</p>
</video>
And in case we want to use a preview image, which may or may not be related to the content, we'll use the poster attribute.
<video controls poster="previa.jpg">
<source src="te.webm" type="video/webm">
<source src="te.mp4" type="video/mp4">
<p>
Your browser does not support the video format, click <a href="te.mp4">here</a> to download it.
</p>
</video>
If you want to use the
autoplayattribute you must accompany it withmuted. It's not allowed to autoplay videos with sound.
Compatibility
There are many video formats but in Web Design the ones that stand out for compatibility and use are:
mp4: Highly recommended with the H264 and AAC codecs.webm: Good quality.
Third-party services: Youtube, Vimeo, etc.
Each platform has its own player. The most common way to integrate it is through an <iframe>.
For example, on Youtube we'll click Share.
:quality(85)/https://andros.dev/static/img/courses/html/8/youtube1.jpg)
Then on Embed.
:quality(85)/https://andros.dev/static/img/courses/html/8/youtube2.jpg)
And the <iframe> tag will be visible. Now we can copy and paste the HTML.
:quality(85)/https://andros.dev/static/img/courses/html/8/youtube3.jpg)
Activity 1
Lay out a website where it's possible to play the latest episodes of your favorite Podcasts.
- Download the
mp3files. - Create a player for each
mp3. - Add their respective logos.
Alternative: If you prefer, you can download music and perform the same tasks.
Activity 2
We're going to make a web page to promote a movie of your choice.
- Get the trailer of a movie.
- Set up a video player.
- Create a table with the technical information: title, duration, actors and year.
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Desafíos de programación atemporales y multiparadigmáticos
Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.
Buy the bookWill you buy me a coffee?
This is how I keep writing without ads or paywalls.
Sure, it's on me!
Comments
There are no comments yet.