Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Podstawy JS :P Nizgodno¶æ typu danych
Forum PHP.pl > Forum > Przedszkole
Szakal
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

  1. function SavePos(){
  2. var expdate = new Date();
  3. expdate.setTime(expdate.getTime() + (5*24*60*60*1000));
  4.  
  5. SetCookie("lastMP3",idPliku,expdate);
  6. SetCookie("cPos",document.getElementById('mp1').CurrentPosition,expdate);
  7.  
  8. }


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:

  1. function LoadLastSound(id) {
  2. idPliku = GetCookie('lastMP3');
  3. var cPos = GetCookie('cPos');
  4. document.getElementById('mp1').filename=plik[idPliku];
  5. document.getElementById('mp1').volume="0";
  6. document.getElementById('mp1').play();
  7. document.getElementById('mp1').CurrentPosition=int(cPos)
  8. }



jednak wywala mi b³±d "Niezgodno¶æ typów" - dlaczego? Za³±czam skrypt...
tzn wiem dlaczego ale jak temu zapobiec ?

Oto ca³y kod:

  1. <!--HEADER-->
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  3. <HTML>
  4. <HEAD>
  5. <meta http-equiv="content-type" content="text/html; charset=iso-8859-2">
  6. <META HTTP-EQUIV="Creation-date" CONTENT="2002.03.16">
  7. <META HTTP-EQUIV="Reply-to" CONTENT="adres zwrotny">
  8. <META NAME="Description" CONTENT="opis dokumentu">
  9. <META NAME="Author" CONTENT="autor dokumentu">
  10. <META NAME="Generator" CONTENT="Zaj±czek 3.0">
  11. <TITLE>My mp3</TITLE>
  12. <STYLE TYPE="text/css">
  13. <!--
  14. .bodytext {
  15. font-size: 11px;
  16. font-family: Tahoma,Verdana,Arial;
  17.  
  18. }
  19. a {
  20. color : #FF6600;
  21. font-size: 11px;
  22. }
  23. a:hover {
  24. color : #FF0000;
  25. font-size: 11px;
  26. }
  27.  
  28. -->
  29. </STYLE>
  30.  
  31. </HEAD>
  32. <BODY onload="LoadLastSound()" OnUnload="SavePos()">
  33. <!--/HEADER-->
  34.  
  35.  
  36. <script language="JavaScript">
  37. <!--
  38. var idPliku;
  39. function LoadSound(dir) {
  40. idPliku=dir;
  41. document.getElementById('mp1').filename=plik[dir];
  42. document.getElementById('mp1').play();
  43. document.getElementById('mp1').volume="0";
  44. }
  45.  
  46. function LoadLastSound(id) {
  47. idPliku = GetCookie('lastMP3');
  48. var cPos = GetCookie('cPos');
  49. document.getElementById('mp1').filename=plik[idPliku];
  50. document.getElementById('mp1').volume="0";
  51. document.getElementById('mp1').play();
  52. document.getElementById('mp1').CurrentPosition=cPos;
  53. }
  54. function SavePos(){
  55. var expdate = new Date();
  56. expdate.setTime(expdate.getTime() + (5*24*60*60*1000));
  57.  
  58. SetCookie("lastMP3",idPliku,expdate);
  59. SetCookie("cPos",document.getElementById('mp1').CurrentPosition,expdate);
  60.  
  61. }
  62. function getCookieVal (offset) {
  63. var endstr = document.cookie.indexOf (";", offset);
  64. if (endstr == -1)
  65. endstr = document.cookie.length;
  66. return unescape(document.cookie.substring(offset, endstr));
  67. }
  68.  
  69. function GetCookie (name) {
  70. var arg = name + "=";
  71. var alen = arg.length;
  72. var clen = document.cookie.length;
  73. var i = 0;
  74. while (i < clen) {
  75. var j = i + alen;
  76. if (document.cookie.substring(i, j) == arg)
  77. return getCookieVal (j);
  78. i = document.cookie.indexOf(" ", i) + 1;
  79. if (i == 0)
  80. break;
  81. }
  82. return null;
  83. }
  84.  
  85. function SetCookie (name, value) {
  86. var argv = SetCookie.arguments;
  87. var argc = SetCookie.arguments.length;
  88. var expires = (argc > 2) ? argv[2] : null;
  89. var path = (argc > 3) ? argv[3] : null;
  90. var domain = (argc > 4) ? argv[4] : null;
  91. var secure = (argc > 5) ? argv[5] : false;
  92. document.cookie = name + "=" + escape (value) +
  93. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  94. ((path == null) ? "" : ("; path=" + path)) +
  95. ((domain == null) ? "" : ("; domain=" + domain)) +
  96. ((secure == true) ? "; secure" : "");
  97. }
  98.  
  99. function DeleteCookie(name) {
  100. var exp = new Date();
  101. FixCookieDate (exp); // Correct for Mac bug
  102. exp.setTime (exp.getTime() - 1); // This cookie is history
  103. var cval = GetCookie (name);
  104. if (cval != null)
  105. document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  106. }
  107.  
  108. setInterval("SpNext()",1000);
  109. function SpNext(){
  110. var Player =document.getElementById('mp1');
  111. if(Player.CurrentPosition==Player.Duration){
  112. idPliku++;
  113. if(plik.length==(idPliku+1)){idPliku=0}{}
  114. LoadSound(idPliku);
  115. }
  116. document.getElementById('PlikScs').innerText=Nazwyplik[idPliku];
  117. document.title="Ozzy Lan Player - "+Nazwyplik[idPliku];
  118. }
  119. //-->
  120. </script>
  121. <div align=center>
  122. <Table width=700 bgcolor=threedface style="border-style:outset; border-width:1px" class=bodytext>
  123. <tr>
  124.  <td class=bodytext>
  125.  <a href=lista.php target="_NEW">Lista ¿yczeñ</a>
  126.  </td>
  127. </tr>
  128. </table><br>
  129. <Table width=700 bgcolor=threedface style="border-style:outset; border-width:1px" class=bodytext>
  130. <tr>
  131.  <td background="bg2.bmp" style="color: #ffffff;font-size: 10px;">
  132.  <TABLE style="color: #ffffff;font-size: 10px;" cellspacing=0 cellpadding=0 border=0><tr><td><B>Ozzy Lan Player&nbsp;-&nbsp;</B></td><td id='PlikScs'></td></tr></table>
  133.  </td>
  134. </tr>
  135. <tr>
  136.  <td>
  137.  <EMBED EndOfStream="alert('ania')" width=696 id="mp1" SRC="../multimed/haendel.mid" LOOP=false AUTOSTART=FALSE HIDDEN=false MASTERSOUND height=45>
  138.  <br>
  139.  Lista plików
  140.  <TABLE border=0 width=100% bgcolor=white style="border-style: inset; border-width:1px" class=bodytext>
  141.  <tr>
  142. <td>
  143.  <?PHP
  144. $i=-1;
  145. $zmienne="var plik = Array(";
  146. $zmienne2="var Nazwyplik = Array(";
  147. if ($handle = opendir('.')) {
  148. while (false !== ($file = readdir($handle))) {
  149. if(($file!=".")&&($file!="..")){
  150. if(is_dir($file)==1){
  151. echo "<b>$file</b><br>";
  152. if ($handle2 = opendir($file."/")) {
  153.  
  154.  while (false !== ($file2 = readdir($handle2))) {
  155.  if(($file2!=".")&&($file2!="..")){
  156.  $next=0;
  157.  switch(strtolower(substr($file2,strlen($file2)-3,strlen($file2)))){
  158.  case "mp3":
  159.  $next=1;
  160.  break;
  161.  
  162.  case "wav":
  163.  $next=1;
  164.  break;
  165.  
  166.  case "mid":
  167.  $next=1;
  168.  break;
  169.  
  170.  case "wma":
  171.  $next=1;
  172.  break;
  173.  }
  174.  if($next==1){
  175.  $i++;
  176.  echo "<a href='java script:LoadSound($i)'>$file2</a>&nbsp;<B>(</B><a href="".$file."/".$file2."">Download</a><B>)</B><br>";
  177.  
  178.  $zmienne.=""".$file."/".$file2."",";
  179.  $zmienne2.=""".$file2."",";
  180.  }
  181.  }
  182.  }
  183. closedir($handle2);
  184. }
  185.  
  186. }
  187. }
  188. }
  189. closedir($handle);
  190.  
  191. echo "<b>Inne</b><br>";
  192. if ($handle2 = opendir(".")) {
  193.  
  194.  while (false !== ($file2 = readdir($handle2))) {
  195.  if(($file2!=".")&&($file2!="..")){
  196.  $next=0;
  197.  switch(strtolower(substr($file2,strlen($file2)-3,strlen($file2)))){
  198.  case "mp3":
  199.  $next=1;
  200.  break;
  201.  
  202.  case "wav":
  203.  $next=1;
  204.  break;
  205.  
  206.  case "mid":
  207.  $next=1;
  208.  break;
  209.  
  210.  case "wma":
  211.  $next=1;
  212.  break;
  213.  }
  214.  if($next==1){
  215.  $i++;
  216.  echo "<a href='java script:LoadSound($i)'>$file2</a>&nbsp;<B>(</B><a href="".$file."/".$file2."">Download</a><B>)</B><br>";
  217.  
  218.  $zmienne.=""".$file2."",";
  219.  $zmienne2.=""".$file2."",";
  220.  }
  221.  }
  222.  }
  223. closedir($handle2);
  224. }
  225. echo "<script language="JavaScript">rn<!--rn";
  226. echo $zmienne.""");";
  227. echo $zmienne2.""");";
  228. echo "//-->rn</script>";
  229. }
  230.  
  231. ?>
  232.  
  233. </td>
  234.  </tr>
  235.  </table>
  236.  <font color=gray>This player is designed by Ozzy (Igor Dirbach)</font>
  237.  </td>
  238. </tr>
  239. </table>
  240. </div>
  241.  
  242.  
  243. <!--FOOTER-->
  244. </BODY>
  245. </HTML>
  246. <!--/FOOTER-->
siemakuba
Proszê o zapoznanie siê z tematem: Temat: Tematyka i zasady panujce na forum Przedszkole a nastêpnie o PW z poprawnym tematem.

Do tego czasu zamkniête.

P.S. i zastanów siê czy nie za du¿o kodu trochê poda³e¶. Czy na prawdê potrzebny jest ca³y ten kawa³?

pozdr.
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.