Я использую плагин jQuery Cycle, чтобы вращать смесь изображений и видео FLV.Для изображений я установил длительность тайм-аута 3000 мс, но для видео он основан на длине видео, и именно здесь начинается моя проблема.Я всегда получаю продолжительность моего первого видео как:
var value = 0;
$(document).ready(function() {
$('.slideshow').cycle({
fx:'scrollLeft,scrollRight',
speed: 1500,
timeoutFn: valueFn
});
function valueFn(currElement, nextElement, opts, isForward){
value = parseInt($('#duration').val());
return value;
}
});
...
...
<div id="image">
<ul class="slideshow">
<?php
$dir = "media/images";
if (is_dir($dir)) {
if (($dh = opendir($dir))) {
$i = 0;
$name = 'FLVPlayer';
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..')
continue;
$ext = explode(".", $file);
if (@$ext[1] == null)
continue;
switch ($ext[1]) {
case "jpg":
echo "<input type=\"hidden\" id=\"duration\" name=\"val\" value=\"3000\" />
<li><img src=\"media/images/" . $file . "\" width=\"848\" height=\"608\" /></li>";
break;
case "flv":
$flv = fopen("media/images/".$file, "rb");
fseek($flv, -4, SEEK_END);
$arr = unpack('N', fread($flv, 4));
$last_tag_offset = $arr[1];
fseek($flv, -($last_tag_offset + 4), SEEK_END);
fseek($flv, 4, SEEK_CUR);
$t0 = fread($flv, 3);
$t1 = fread($flv, 1);
$arr = unpack('N', $t1 . $t0);
$milliseconds_duration = $arr[1];
$milliseconds_duration;
$html = <<<HTML
<input type="hidden" id="duration" value="{$milliseconds_duration}" />
<li>
<div id="container{$i}">Loading the player ...</div>
<script type="text/javascript">
jwplayer("container{$i}").setup({
flashplayer: "js/player.swf",
file: "media/images/{$file}",
height: 608,
width: 848,
"controlbar.idlehide": true,
icons: false,
events: {
onReady: function() { this.play(); }
}
});
</script>
</li>
HTML;
echo $html;
$i++;
break;
case "txt":
$myFile = "media/images/" . $file;
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo "<li>" . $theData . "</li>";
break;
}
}
}
closedir($dh);
}
?>
код PHP просто проходит через каталог, ищет файлы и выводит соответствующий код HTML для FLV, изображений или текста.Если я использую фиксированное значение тайм-аута, то все остальное работает просто отлично.