Chapter 7 Working With Multimedia
Chapter 7 Working With Multimedia
1
Objectives XP
2
Objectives (continued) XP
3
Introducing Multimedia on the WebXP
• HTML is the perfect tool to share text and data
• The next major phase in HTML language was
the introduction of multimedia support
• Streaming audio, video, and interactive games,
made the web a dominant entertainment
platform
• One of the biggest challenges
– Delivering multimedia content in a form that can
be retrieved quickly and easily without loss of
quality
4
Understanding Codecs and ContainersXP
• Codec: Computer program that encodes and
decodes streams of data
• Codecs compress data to transmit it in fast and
efficient manner
• Codecs decompress data when it is to be read
or played back
5
Understanding Codecs and Containers XP
(continued 1)
• The compression method can be either lossy
or lossless
• Lossy compression: Nonessential data is
removed in order to achieve a smaller file size
– Example:
• An audio file might be compressed by removing sounds
that the human ear can barely hear
6
Understanding Codecs and Containers XP
(continued 2)
– The more the file is compressed, the more the
content is lost
– Data removed during compression cannot be
recovered
• Lossless compression: Data is compressed by
removing redundant information
– Example:
• AAAABBBBBCCCCCC requires 15 characters of
information, which can be rewritten using 6 characters
as 4A5B6C
7
Understanding Codecs and Containers XP
(continued 3)
– Lossless compression cannot achieve the same level of
compression as with lossy compression
• Codecs are placed within a container that handles the
packaging, transportation and presentation of data
• Container is the file format identified by a file extension
<audio controls>
<source src="love.ogg" type="audio/ogg; codecs=vorbis"/>
<source src="love.mp4" type="audio/mp4; codecs=aac "/>
</audio>
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_audio_controls
8
XP
<audio controls>
<source src="love.ogg" type="audio/ogg; codecs=vorbis"/>
<source src="love.mp4" type="audio/mp4; codecs=aac "/>
</audio> 9
Understanding Codecs and Containers XP
<audio controls>
(continued
<source 4) type="audio/ogg; codecs=vorbis"/>
src="love.ogg"
• The src="love.mp4"
<source web supports a multitude of container andcodecs=aac
type="audio/mp4; codec combinations
"/>
• Not all containers and codecs are equally supported
</audio>
10
Understanding Plug-Ins XP
11
Understanding Plug-Ins (continued 1)XP
• Problems with the plug-in approach for delivery
of multimedia content
– Plugs-ins require users to install a separate
application in addition to their web browsers
– A common plug-in is not available across all
browsers, operating systems, and devices
– HTML documents that support multiple plug-ins are
difficult to create and maintain
12
Understanding Plug-Ins (continued 2)XP
– Plug-ins consume valuable system resources,
resulting in slow and unreliable performance
– Plug-ins are a security risk with some of the most
prominent Internet attacks working their way into
browsers via a plug-in
13
Working with the audio ElementXP
• Audio clips are embedded within a web page using audio
element
<audio src=“url” attributes />
where url specifies the source of the audio file and
attributes define how the audio clip should be handled by
the browser
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_audio_controls
<audio controls>
<source src="love.ogg" type="audio/ogg; codecs=vorbis"/>
<source src="love.mp4" type="audio/mp4 codecs=aac; "/>
</audio>
audio_with_multiple_sources.html
14
Working with the audio Element (continued) XP
https://www.w3schools.com/tags/tag_audio.asp
https://www.w3schools.com/tags/
att_audio_controls.asp
https://www.w3schools.com/tags/att_audio_loop.asp
https://www.w3schools.com/tags/att_audio_muted.asp
https://www.w3schools.com/tags/att_audio_preload.asp
preload=none default
https://www.w3schools.com/tags/att_audio_src.asp
15
https://www.w3sch
Browsers and Audio Formats ools.com/tags/tryit.
XP
asp?filename=tryht
ml5_audio_controls
<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>>
16
XP
Browsers and Audio Formats (continued 1)
<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>>
17
XP
Browsers and Audio Formats (continued 2)
• Nest several source elements within a single audio element
to provide several versions of the same media file
<audio>
<source src=“url1” type=“mime-type” />
<source src=“url2” type=“mime-type” />
… </audio>
where, url1, url2,… are the URLs for each audio file and
mime-type specifies the audio format associated with each file
<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>>
18
XP
Browsers and Audio Formats (continued 3)
Google
chrome
Internet Explorer 20
Providing a Fall-back to an Audio ClipXP
https://www.w3schoo
ls.com/cssref/css3_pr
_box-shadow.asp
https://www.w3schools.
com/cssref/tryit.asp?file
name=trycss3_box-shad
ow
22
Plug-In Attributes XP
23
XP
24
Plug-Ins as Fallback Options XP
26
Video Formats and Codecs (continued 1)
XP
audiovideo_with_multiple_sources.html
27
Video Formats and Codecs (continued 2)
XP
audiovideo_with_multiple_sources.html
28
Using the HTML5 video ElementXP
• Videos are embedded into a web page using video element
<video attributes>
<source src=“url1” type=“mime-type” />
<source src=“url2” type=“mime-type” />
… </video>
where attributes are HTML attributes that control the behaviour and
appearance of the video playback, url1, url2,… are the possible sources
of the video
<video controls tabindex="0" poster="Desert.jpg" autoplay loop>
<source src="mov_bbb.webm" type="video/webm">
<source src="mov_bbb.mp4" type="video/mp4">
<source src="mov_bbb.ogg" type="video/ogg">
</video>
audiovideo_with_multiple_sources.html
https://www.w3schools.com/html/html5_video.asp
29
Using the HTML5 video Element XP
(continued 1)
mime-type specifies the format associated with each video file
30
Using the HTML5 video Element XP
(continued 2) audiovideo_with_multiple_sources.html
31
Using the HTML5 video Element XP
(continued 3)
• poster attribute defines a video’s preview image
<video poster=”url”>
…
</video>
where url points to an image file containing the preview image
• poster attribute is used as a placeholder image that is displayed when a video is
being downloaded
33
Adding a Text Track to Video (continued 1)XP
<track kind=“type” src=“url” label=“text” srclang=“lang”
/>
where,
– kind attribute defines the track type
– src attribute references a file containing the track text
– label attribute gives the track name
– srclang attribute indicates the language of the track
34
Adding a Text Track to Video (continued 2)XP
• Tracks are stored as simple text files written in Web Video Text
Tracks or WebVTT language
• Format of a WebVTT file
WEBVTT
cue1
cue2
…
where cue1, cue2,… are cues matched with specific time
intervals within a media clip
https://www.youtube.com/watch?v=Gc1xyxV7K5M
https://www.3playmedia.com/2017/06/30/how-to-create-a-webvtt-file/
36
Making Tracks with WebVTT (continued 1)XP
• List of cues is separated by a single blank line after a cue text
• White space is not ignored in WebVTT files
• General form of a cue
label
start --> stop
cue text
where label is the name assigned to the cue, start and stop
define the time interval, and cue text is the text of the cue
37
XP
General form of a
cue
label
start --> stop
cue text
38
XP
39
cp_captions.vtt
XP
41
Placing the Cue Text (continued 1)XP
42
Size and position of a cue text / text track XP
text
cue 43
Applying Styles to Track Cues XP
44
Applying Styles to Track Cues (continued 1) XP
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ruby
45
Applying Styles to Track Cues (continued 2) XP
46
https://www.youtube.com/watch?v=Gc1xyxV7K5M
cp_captions.vtt https://www.3playmedia.com/2017/06/30/how-to-
create-a-webvtt-file/ XP
cp_loyal.html
<link href="cp_media.css" rel="stylesheet" />
:
<video controls poster="cp_photo2.png".>
<source src="cp_dance.mp4" type="video/mp4" />
<source src="cp_dance.webm" type="video/webm" />
<track kind="captions" label="Dance Captions" src="cp_captions.vtt" default />
<p><em>To play this video clip, your browser needs to
support HTML5.</em></p>
</video> 47
XP
cue
text
49
Adding a Text Track to Video XP
50
Adding a Text Track to Video (continued 1)XP
<track kind=“type” src=“url” label=“text” srclang=“lang”
/>
where,
– kind attribute defines the track type
– src attribute references a file containing the track text
– label attribute gives the track name
– srclang attribute indicates the language of the track
51
Adding a Text Track to Video (continued 2)XP
53
video_on_wmv
Exploring the Flash Player XP
https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_param
• The most-used plug-in for video playback is Adobe Flash player embedded
using the following object element:
<object data=“url” type=“application/x-shockwave-flash”
width=“value” height=“value”>
<param name=“movie” value=“url” /> parameters
</object>
55
Exploring the Flash Player (continued) XP
56
Embedding Videos from YouTube XP
• YouTube videos are easy to embed in a web
page using YouTube’s HTML5 video player
• Click the Share button below the YouTube
video player to share it
• YouTube provides options to post a hypertext
link to the video to a multitude of social media
sites or to share the link via e-mail
https://www.youtube.com/watch?v=xrP7IERmKDk
57
Embedding Videos from YouTube XP
(continued 1)
• To embed a video within a website, click Embed, which brings up a preview
of the embedded player and the HTML code that needs to be added to the
web page
• iframe element: Used to mark inline frames
• Inline frames: Windows embedded within a web page that display the
content of another page or Internet resource
• The general code for the embedded player is
<iframe width=“value” height=“value” src=“url”
frameborder=“0” allowfullscreen>
</iframe>
where, the url provides the link to the
YouTube video
– width and height attributes define the dimensions of the
player embedded on a web page
– frameborder attribute sets the width of the border around
the player in pixels
– allowfullscreen attribute allows the user to play the
video in full screen mode
<br/>
<br/>
61
XP
https://www.w3schools.com/html/tryit.asp?file
Iframe name=tryhtml_iframe_target
<!DOCTYPE html>
<html>
<body>
<h2>Iframe - Target for a Link</h2>
<iframe height="300px" width="100%"
src="demo_iframe.htm" name="iframe_a">
</iframe>
<p> <a href="https://www.w3schools.com"
target="iframe_a"> W3Schools.com </a> </p>
<p>When the target of a link matches the name
of an iframe, the link will open in the
iframe.</p>
</body>
</html>
HTML5 Video Players XP
63
HTML5 Video Players (continued) XP
• HTML5 includes the following video players:
– JWPlayer (www.jwplayer.com)
– Video.js (www.videojs.com)
– MediaElement.js (mediaelementjs.com)
– Projekktor (www.projekktor.com)
– Flowplayer/Flash player (flowplayer.org)
64
Introducing Transitions XP
• Transition: Change in an object’s style from the initial state to the ending
state, usually in response to an event initiated by the user or the browser
• It slows down the change from one color to another and provides
intermediate styles
65
XP
66
Introducing Transitions (continued) XP
• To create transition, employ the following transition style:
transition: property duration;
where,
– property is a property of the object that changes between the
initial and end states
– duration is the transition time in seconds or milliseconds
https://www.w3schools.com/css/tryit.asp?filename=trycss3_transition2
67
Setting the Transition Timing XP
68
ease: (the default) Transition occurs more rapidly at the beginning and slows down near the
end XP
ease-in: Transition starts slowly and maintains a constant rate until the finish
ease-out: Transition starts at a constant rate and then slows down toward the finish
ease-in-out: Transition starts slowly, reaches a constant rate, and then slows down toward the
finish
linear: Transition is applied at a constant rate throughout the duration
o https://www.w3scho
ols.com/css/css3_tra
nsitions.asp
https://www.w3schools.com/css/tryit.asp?filename=trycss3_transition_speed
69
Setting the Transition Timing XP
(continued 2)
• Timing function can be visualized as a graph
• It shows the progress of transition vs. duration
• The graphical representation of the timing
function is the basis of another measure of
transition timing using
cubic-bezier(n, n, n, n)
where n parameter values define the shape of
the timing curve
https://www.w3schools.com/cssref/tryit.asp?filename=trycss_func_cubic-bezier
70
#div1 {transition-timing-function: linear;}
or XP
#div1 { transition-timing-function: cubic-bezier(0, 0, 1, 1);
cubic-bezier(0.42,0,1,1) cubic-bezier(0,0,1,1)
74
XP
75
https://www.w3schools.com/css/css3_2dtransforms.asp animation1.html
OR
nav#topLinks a { XP
color: rgb(255, 255, 255);
text-shadow: rgba(0, 0, 0, 1) 1px -1px 1px;
transform: scale(1,1) translateY(0px);
transition: all 1.2s linear; }
nav#topLinks a:hover {
color: rgb(255, 183, 25);
text-shadow: rgba(0, 0, 0, 0.5) 0px 15px 4px;
transform: scale(2,2) translateY(-15px); }
The scale() method increases or
decreases the size of an element
(according to the parameters given The translate() method moves an element from its
for the width and height). current position (according to the parameters given
The following example increases the for the X-axis and the Y-axis).
The following example moves the <div> element 50
<div> element to be two times of pixels to the right, and 100 pixels down from its
its original width, and three times of current position:
its original height:
div { transform: scale(2, 3);} div { transform: translate(50px, 100px); }
translate(x,y) Defines a 2D translation, moving the element along the X- and the Y-axis
77
<!DOCTYPE html> @keyframes Rule
<html>
<head>
@keyframes name {
keyframe1 {styles;}
XP
<style> keyframe2 {styles;}
div { width: 100px; height: 100px; background: red; position: relative;
…}
animation: mymove 5s infinite; animation-timing-function: linear; }
@keyframes mymove { or
from {left: 0px;} @keyframes mymove {
to {left: 200px;} 0% {left: 0px;}
} 100% {left: 200px;}
</style> }
</head>
<body>
<h1>The animation-timing-function Property</h1>
<p>Play an animation with the same speed from beginning to end:</p>
<div></div>
<p><strong>Note:</strong> The animation-timing-function property is
not supported in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_animation-timing-function
XP
animation1.html
10 sec
79
Applying an Animation XP
80
animation: name duration timing-function delay iteration-count direction fill-mode play-
state;
XP
animation: mymove 5s infinite;
or
animation-name: mymove
animation-duration:5s
animation-iteration-count: infinite
https://www.w3scho
ols.com/cssref/css3_
pr_animation.asp
81
Controlling an Animation XP
82
Controlling an Animation (continued 2)XP
• Check box can be replaced with more
attractive icons
• Display symbol to run the animation
• Display symbol to pause the animation
• The two symbols have the Unicode values \
21bb and \270b, respectively
83
<input type="checkbox" id="rotateVideo" />
<label for="rotateVideo"> </label> XP
84
cp_loyal.html open cp_loyal.html
from tutorial folder XP
<link href="cp_media.css" rel="stylesheet" />
<link href="cp_animate.css" rel="stylesheet" />
<script src="cp_spin.js"></script>
</head>
<body>
:
<p>↻to rotate and play the video. Click ✋ to pause the rotation and
the playback.
</p>
<input type="checkbox" id="rotateVideo" />
<label for="rotateVideo"> </label>
<video controls poster="cp_photo2.png".>
<source src="cp_dance.mp4" type="video/mp4" />
<source src="cp_dance.webm" type="video/webm" />
<track kind="captions" label="Dance Captions" src="cp_captions.vtt" default/>
<p><em>To play this video clip, your browser needs to support HTML5.
</em></p>
</video>
85
cp_animate.css https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_border-radius
open cp_animate.css
and cp_royal.html from
cp_royal.html
tutorial folder
XP
86
XP
87
https://www.w3schools.com/css/css_selectors.asp
https://www.w3schools.com/css/css_combinators.asp
a person who XP
is related to you and h1, h2{color: red;}
who lives after you, such
as your child or grandchi h1{color: red;}
ld/ your children or
grandchildren
• Pseudo-class – classifies an element based on its current status, position, or use in the
document
element: pseudo-class
where element is an element from the document and pseudo-class is the
name of a css pseudo-class
– 1 .Structural pseudo-class – classifies an element based on its location within the
structure of the HTML document
input#rotateVideo:not(:checked)+label::after { content: "\21bb"; }
89
Generating Content with CSS https://www.w3schools.com/cssref/tryit.asp?filename=trycss_sel_before
XP
• New content can be added either before or after an element using the following
before and after pseudo-elements:
element::before {content: text;}
element::after {content: text;}
where text is the content to be inserted into the rendered web page
input#rotateVideo:not(:checked)+label::after { content: "\21bb"; }
90
XP
• Limitations of transition
– It can only be run when a CSS property is being
changed, such as during the hover event
– It is run once and cannot be looped for repetition
– Initial and end states of the transition can be
defined but not the styles of intermediate states
• Animation is created to overcome the limitations
https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_animation-play-state_hover
91