Jump to content

Recommended Posts

Posted (edited)

Boa Noite,

Estou aqui com um problema, que é o seguinte, eu estive a pesquisar exemplos na internet sobre HTML5 como ver a duração do video, o tempo de reprodução, etc. O que acontece é que tem 2 funções que uma dá o tempo total do video, e outra dá a o tempo de reprodução. O que acontece é que queria fazer era calcular o tempo de reprodução em segundos. Mas não estou a conseguir, segui como estava no código originalmente mas não estou a conseguir.

PS: Eu criei a função convertSeconds.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML5 Video</title>
</head>
<body>

<p>
<button id="play">PLAY</button>
<button id="pause">PAUSE</button>
</p>
<video id="video" src="lol.mp4" width="800" height="600" controls></video>
<p id="duration"></p>
<p id="currenttime"></p>
<p id="ola"></p>

<script>
var myVideo = document.getElementById("video");
var btnPlay = document.getElementById("play");
var btnPause = document.getElementById("pause");
var textduration = document.getElementById("duration");
var textcurrenttime = document.getElementById("currenttime");
var textseconds = document.getElementById("ola");

btnPlay.addEventListener("click", function(){myVideo.play();}, false);
btnPause.addEventListener("click", function(){myVideo.pause();}, false);

myVideo.addEventListener("loadedmetadata",
function(){textduration.innerHTML = "Duration: " + convertTime(myVideo.duration);},
false);

myVideo.addEventListener("timeupdate",
function(){textcurrenttime.innerHTML = "Current Time: " + convertTime(myVideo.currentTime);},
false);

myVideo.addEventListener("secondupdate",
function(){textseconds.innerHTML = "Seconds: " + convertTime(myVideo.currentTime);},
false);


function convertSeconds(org){
var minute = Math.floor(org*60) % 60;
var second = Math.floor(org%60);
var seconds = (minute*60)+second;
return seconds;
}

function convertTime(org){
var minute = Math.floor(org/60) % 60;
var second = Math.floor(org%60);
return( minute + ' : ' + second);
}

function saltar(tempo){
var vid = document.getElementById("video");
document.getElementById("video").currentTime = tempo;
vid.pause();
}
</script>
Momento 1 - <button onclick="saltar(8)">Saltar</button><br>
Momento 2 - <button onclick="saltar(14)">Saltar</button><br>
Momento 3 - <button onclick="saltar(172)">Saltar</button><br>
</body>
</html>

Obrigado 🙂

Edited by brunoais
geshi + título muito melhorado

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.