-
video preview
salve a tutti cercando su internet ho trovato questo script per recuperare il primo frame di un video e trasformarlo in un canvas da utilizzare come anteprima video:
Codice PHP:
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var i = 0;
var video = document.createElement("video");
var thumbs = document.getElementById("thumbs<? echo $id ?>");
video.addEventListener('loadeddata', function() {
thumbs.innerHTML = "";
video.currentTime = i;
}, false);
video.addEventListener('seeked', function() {
// now video has seeked and current frames will show
// at the time as we expect
generateThumbnail(i);
// when frame is captured, increase
i++;
// if we are not passed end, seek to next interval
if (i < 1) {
// this will trigger another seeked event
video.currentTime = i;
}
}, false);
video.preload = "auto";
video.src = "URL DEL VIDEO";
function generateThumbnail() {
var c = document.createElement("canvas");
var ctx = c.getContext("2d");
c.width = 1500;
c.height = 1500;
ctx.drawImage(video, 1, 1, 200, 200);
thumbs.appendChild(c);
}
}//]]>
</script>
<div id="thumbs<? echo $id ?>">..</div><br/>
e fin qui lo script funziona bene il problema è che in un ciclo
Codice PHP:
while{mysql_fetch_array}
non funziona per niente ho provato con include(),js load() a includere direttamente lo script nell ordinamento dei video ma non si vede l anteprima....
vorrei provare a trasformare il canvas in un file png per poi memorizzarlo in una cartella o sul database ma sono andato letteralmente in tilt...
Qualcuno può suggerirmi come posso fare ??
-
mysql_fetch_array è una funzione, dove sono le parendesi tonte?
Oltre al fatto di non aver postato tutto il codice la funzione non si usa cosi, studia meglio il php e soprattutto come gestire mysql con php.
P.S.: Le funzioni mysql saranno presto deplecate e sostituite da mysqli
-
il ciclo che intendevo è questo:
Codice:
<?php
while($go = mysql_fetch_array($query)){
$id = $go['id']; ?>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var i = 0;
var video = document.createElement("video");
var thumbs = document.getElementById("thumbs<? echo $id ?>");
video.addEventListener('loadeddata', function() {
thumbs.innerHTML = "";
video.currentTime = i;
}, false);
video.addEventListener('seeked', function() {
// now video has seeked and current frames will show
// at the time as we expect
generateThumbnail(i);
// when frame is captured, increase
i++;
// if we are not passed end, seek to next interval
if (i < 1) {
// this will trigger another seeked event
video.currentTime = i;
}
}, false);
video.preload = "auto";
video.src = "URL DEL VIDEO";
function generateThumbnail() {
var c = document.createElement("canvas");
var ctx = c.getContext("2d");
c.width = 1500;
c.height = 1500;
ctx.drawImage(video, 1, 1, 200, 200);
thumbs.appendChild(c);
}
}//]]>
</script>
<div id="thumbs<? echo $id ?>">..</div><br/><? } ?>
le regole del php le conosco bene il javascript un pò meno,comunque sia se questo codice lo faccio funzionare con un solo Url del file video funziona benissimo, utilizzando l'ordinamento tramite mysql_fetch_array() (dove i files video sono molti di più) mi visualizza un solo canvas mentre a me serve che visualizzi l anteprima di ogni video...
come mai non mi funziona nel secondo caso ????
(lo script qui sopra è da esempio lho fatto senza provarlo ma piu o meno è lo stesso che ho sul sito dal lato del php mentre il javascript è un copia e incolla)