Advertisement
emcniece

Niftyplayer for Kusaba X v1.0 - Loader PHP and Javascript

May 25th, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1.  <?php
  2. /* Niftyplayer For Kusaba X v1.0
  3. ** Loader PHP and Javascript
  4. ** Paste this directly above the </body>
  5. ** tag in your dwoo/templates/menu.tpl
  6. ** page, and edit the first few variables.
  7. **
  8. ** $existing_file - [OPTIONAL] if you can, it might help you
  9. ** at some point to troubleshoot.
  10. **
  11. ** $path_abs - [REQUIRED] this is the absolute server path
  12. ** to your music directory. In the example, public_html is
  13. ** the directory of the actual website top level, /mu/ is
  14. ** the /mu/sic board, and /src/ is where the actual music
  15. ** is stored after its uploaded. NO TRAILING SLASH!!
  16. **
  17. ** var path - [REQUIRED] the javascript variable for the
  18. ** local system path to the music folder. This should be
  19. ** in reference to your actual menu.php file, not the
  20. ** menu.tpl template. In most cases, this will be right
  21. ** off the home public_html/ directory.
  22. **
  23. */
  24.  
  25.   $existing_file = "file you know exists in your music dir";
  26.   $path_abs = "/home/username/public_html/mu/src";
  27.  
  28.  
  29.      $list = array();
  30.       $error = FALSE;
  31.       $handle = opendir($path_abs);
  32.       if ($handle) {
  33.         while (FALSE !== ($file = readdir($handle))) {
  34.           if (substr($file, -4) === '.mp3') {
  35.             $list[] = $file;
  36.           }
  37.         }
  38.         closedir($handle);
  39.       }
  40.       else {
  41.         // Here's a file we know exists
  42.         $error = TRUE;
  43.         $list = array($existing_file);
  44.       }
  45.     ?>
  46.     <script type="text/javascript">
  47.  
  48.     // Local path to music directory, keep slashes off beginning
  49.     // and on the end!
  50.     var path = new String("mu/src/");
  51.  
  52.     var list = <?php print json_encode($list); ?>;
  53.     document.getElementById('play-mp3').onclick = function (event) {
  54.       var song = list[Math.floor(Math.random()*list.length)];
  55.       niftyplayer('niftyPlayer1').loadAndPlay(path + encodeURIComponent(song));
  56.       document.getElementById('playing').innerHTML=song;
  57.       event.preventDefault();
  58.       return false;
  59.     };
  60.     </script>
  61.     <?php if ($error): ?>
  62.       <div style="display:none;">Error reading path.</div>
  63.     <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement