Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

Media Position and Duration

Previously, we learned about how we can play audio and video content, control playback of media, and adjust the volume of media. In this section, we will learn about media position and duration. When we work with media, we also often want to know how long a specific media piece is and where we are in that specific piece of media.

These are the following steps used to get the media position and duration.

1) Create index3.html

We will create a new html file namely index3.html with the same content present in the index.html. We will make changes in the index3.html file without affecting the code present in the index.html.

Media Position and Duration

2) Create an output field in the user interface

Now, we will create output fields for position and duration using <output></output> tags. These output tags are used to show media position and duration in the following way:

3) outDuration

Now, we will get the outDuration field using Id and assign the duration of the player by converting minutes into seconds in the following way:


Media Position and Duration

4) outPosition

Now, we will find the interval by using the setInterval() function. This function contains two arguments, i.e., display time and duration. We will create displayTime function outside the window.onload function in the following way:


Media Position and Duration

Complete Code:







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA