I would like to know how I can calculate and display the length of time for online videos that are in media files by remote URL using this URL # to give the duration of the video in case.
I would like to know how I can calculate and display the length of time for online videos that are in media files by remote URL using this URL # to give the duration of the video in case.
I suggest you take a look at getID3
You can access the page at this link!
getID3
is a php class to see the attributes of a file, see the following example;
<?php
Include ("getid3/getid3.php");
$filename="nome_do_video.mp4";
$getID3 = new getID3;
$file = $getID3->analize($filename);
echo $file['playtime_string'];
?>
If there is any doubt, check the demo
page on the getID3
site
I have a solution in Javascript . I know you wanted to PHP
, but this form below is more advisable as it works directly with the properties of the video without the need for API , EXECUTE THE CODE BELOW ( comentários no código
):
//Criando as funcionalidades do video
var myVideo=document.getElementById("video1");
function playPause()
{
if (myVideo.paused)
myVideo.play();
else
myVideo.pause();
}
function muteUnMute()
{
if( !myVideo.muted)
myVideo.muted='muted';
else
myVideo.muted=false;
}
//Criando as propriedades do video
var videoStartTime = 0;
var durationTime = 0;
myVideo.addEventListener('loadedmetadata', function() {
//DETERMINADO PONTO DE PARTIDA DO VÍDEO
videoStartTime = 0;
//DURAÇÃO DO VÍDEO PROGRAMADA
durationTime = 10;
this.currentTime = videoStartTime;
}, false);
//Função que conta o progresso do vídeo
myVideo.addEventListener('timeupdate', function() {
//Setando na div o a duração do vídeo
var div = document.getElementById('tempo');
div.innerHTML = this.currentTime;
//Condição para pausar o video em determinado tempo
if(this.currentTime > videoStartTime + durationTime){
this.pause();
}
});
<div style="text-align:center">
<h3>Contando o tempo: </h3><div id="tempo" style="color: red"></div>
<button onclick="playPause()">Play/Pausar</button>
<button onclick="muteUnMute()">SemSom/comSom</button>
<br>
<video id="video1" width="420">
<source src="mov_bbb.mp4" type="video/mp4">
<source src="http://thumb.mais.uol.com.br/13277141.mp4"type="video/ogg">
Seu browser não suporta HTML5 video.
</video>
</div>