Java Reference
In-Depth Information
The
playbackClick()
function is logically identical to
muteClick()
. After you set the target and video,
you then determine whether you need to play or pause the video. You can accomplish this easily with
the media object's
paused
property:
function playbackClick(e) {
var target = e.target;
var video = document.getElementById("bbbVideo");
if (video.paused) {
video.play();
target.innerHTML = "Pause";
}
If it's
true
, you call the
play()
method to either start or resume playback. If
paused
is
false
, you want
to pause playback:
else {
video.pause();
target.innerHTML = "Resume";
}
}
You do so with the
pause()
method, and you change the button's text to Resume. The word "resume"
was chosen to enhance the user's experience; people expect to resume from a paused state. You could
have implemented something similar in Example 1, but because the video's state was determined by the
text of a button, it would've required extra code to make it work.
Now, this example is a marked improvement over Example 1, but it still has an issue: Users can
control the video through the context menu (Figure 15-6).
figure 15-6