Witam, napisałem skrypcik czytający muzykę w katalogu i umożliwiający jej odtworzenie... Skrypt po wyłączeniu okna zapisuje 2 cookies 1. Nazwa ostatnio odtwarzanego utworu (a togładniej jego index w tabeli) i pozycja currenta(suwaka sekundowego) Windows Media Player'a
function SavePos(){
var expdate = new Date();
expdate.setTime(expdate.getTime() + (5*24*60*60*1000));
SetCookie("lastMP3",idPliku,expdate);
SetCookie("cPos",document.getElementById('mp1').CurrentPosition,expdate);
}
document.getElementById('mp1').CurrentPosition - ta wartość odpowiada za położenie sekundnika i jest zapisywana w postaci: np. "3,234556"
i odtworzenie danych z cookie:
function LoadLastSound(id) {
idPliku = GetCookie('lastMP3');
var cPos = GetCookie('cPos');
document.getElementById('mp1').filename=plik[idPliku];
document.getElementById('mp1').volume="0";
document.getElementById('mp1').play();
document.getElementById('mp1').CurrentPosition=int(cPos)
}
jednak wywala mi błąd "Niezgodność typów" - dlaczego? Załączam skrypt...
tzn wiem dlaczego ale jak temu zapobiec ?
Oto cały kod:
<!--HEADER-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2">
<META HTTP-EQUIV="Creation-date" CONTENT="2002.03.16">
<META HTTP-EQUIV="Reply-to" CONTENT="adres zwrotny">
<META NAME="Description" CONTENT="opis dokumentu">
<META NAME="Author" CONTENT="autor dokumentu">
<META NAME="Generator" CONTENT="Zajączek 3.0">
<TITLE>My mp3</TITLE>
<STYLE TYPE="text/css">
<!--
.bodytext {
font-size: 11px;
font-family: Tahoma,Verdana,Arial;
}
a {
color : #FF6600;
font-size: 11px;
}
a:hover {
color : #FF0000;
font-size: 11px;
}
-->
</STYLE>
</HEAD>
<BODY onload="LoadLastSound()" OnUnload="SavePos()">
<!--/HEADER-->
<script language="JavaScript">
<!--
var idPliku;
function LoadSound(dir) {
idPliku=dir;
document.getElementById('mp1').filename=plik[dir];
document.getElementById('mp1').play();
document.getElementById('mp1').volume="0";
}
function LoadLastSound(id) {
idPliku = GetCookie('lastMP3');
var cPos = GetCookie('cPos');
document.getElementById('mp1').filename=plik[idPliku];
document.getElementById('mp1').volume="0";
document.getElementById('mp1').play();
document.getElementById('mp1').CurrentPosition=cPos;
}
function SavePos(){
var expdate = new Date();
expdate.setTime(expdate.getTime() + (5*24*60*60*1000));
SetCookie("lastMP3",idPliku,expdate);
SetCookie("cPos",document.getElementById('mp1').CurrentPosition,expdate);
}
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie(name) {
var exp = new Date();
FixCookieDate (exp); // Correct for Mac bug
exp.setTime (exp.getTime() - 1); // This cookie is history
var cval = GetCookie (name);
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
setInterval("SpNext()",1000);
function SpNext(){
var Player =document.getElementById('mp1');
if(Player.CurrentPosition==Player.Duration){
idPliku++;
if(plik.length==(idPliku+1)){idPliku=0}{}
LoadSound(idPliku);
}
document.getElementById('PlikScs').innerText=Nazwyplik[idPliku];
document.title="Ozzy Lan Player - "+Nazwyplik[idPliku];
}
//-->
</script>
<div align=center>
<Table width=700 bgcolor=threedface style="border-style:outset; border-width:1px" class=bodytext>
<tr>
<td class=bodytext>
<a href=lista.php target="_NEW">Lista życzeń</a>
</td>
</tr>
</table><br>
<Table width=700 bgcolor=threedface style="border-style:outset; border-width:1px" class=bodytext>
<tr>
<td background="bg2.bmp" style="color: #ffffff;font-size: 10px;">
<TABLE style="color: #ffffff;font-size: 10px;" cellspacing=0 cellpadding=0 border=0><tr><td><B>Ozzy Lan Player - </B></td><td id='PlikScs'></td></tr></table>
</td>
</tr>
<tr>
<td>
<EMBED EndOfStream="alert('ania')" width=696 id="mp1" SRC="../multimed/haendel.mid" LOOP=false AUTOSTART=FALSE HIDDEN=false MASTERSOUND height=45>
<br>
Lista plików
<TABLE border=0 width=100% bgcolor=white style="border-style: inset; border-width:1px" class=bodytext>
<tr>
<td>
<?PHP
$i=-1;
$zmienne="var plik = Array(";
$zmienne2="var Nazwyplik = Array(";
while (false !== ($file = readdir($handle))) { if(($file!=".")&&($file!="..")){
if ($handle2 = opendir($file."/")) {
while (false !== ($file2 = readdir($handle2))) { if(($file2!=".")&&($file2!="..")){
$next=0;
case "mp3":
$next=1;
break;
case "wav":
$next=1;
break;
case "mid":
$next=1;
break;
case "wma":
$next=1;
break;
}
if($next==1){
$i++;
echo "<a href='java script:LoadSound($i)'>$file2</a> <B>(</B><a href="".$file."/".$file2."">Download</a><B>)</B><br>";
$zmienne.=""".$file."/".$file2."",";
$zmienne2.=""".$file2."",";
}
}
}
}
}
}
}
while (false !== ($file2 = readdir($handle2))) { if(($file2!=".")&&($file2!="..")){
$next=0;
case "mp3":
$next=1;
break;
case "wav":
$next=1;
break;
case "mid":
$next=1;
break;
case "wma":
$next=1;
break;
}
if($next==1){
$i++;
echo "<a href='java script:LoadSound($i)'>$file2</a> <B>(</B><a href="".$file."/".$file2."">Download</a><B>)</B><br>";
$zmienne.=""".$file2."",";
$zmienne2.=""".$file2."",";
}
}
}
}
echo "<script language="JavaScript
">rn<!--rn"; }
?>
</td>
</tr>
</table>
<font color=gray>This player is designed by Ozzy (Igor Dirbach)</font>
</td>
</tr>
</table>
</div>
<!--FOOTER-->
</BODY>
</HTML>
<!--/FOOTER-->