Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Niftyplayer For Kusaba X v1.0
- ** Loader PHP and Javascript
- ** Paste this directly above the </body>
- ** tag in your dwoo/templates/menu.tpl
- ** page, and edit the first few variables.
- **
- ** $existing_file - [OPTIONAL] if you can, it might help you
- ** at some point to troubleshoot.
- **
- ** $path_abs - [REQUIRED] this is the absolute server path
- ** to your music directory. In the example, public_html is
- ** the directory of the actual website top level, /mu/ is
- ** the /mu/sic board, and /src/ is where the actual music
- ** is stored after its uploaded. NO TRAILING SLASH!!
- **
- ** var path - [REQUIRED] the javascript variable for the
- ** local system path to the music folder. This should be
- ** in reference to your actual menu.php file, not the
- ** menu.tpl template. In most cases, this will be right
- ** off the home public_html/ directory.
- **
- */
- $existing_file = "file you know exists in your music dir";
- $path_abs = "/home/username/public_html/mu/src";
- $list = array();
- $error = FALSE;
- $handle = opendir($path_abs);
- if ($handle) {
- while (FALSE !== ($file = readdir($handle))) {
- if (substr($file, -4) === '.mp3') {
- $list[] = $file;
- }
- }
- closedir($handle);
- }
- else {
- // Here's a file we know exists
- $error = TRUE;
- $list = array($existing_file);
- }
- ?>
- <script type="text/javascript">
- // Local path to music directory, keep slashes off beginning
- // and on the end!
- var path = new String("mu/src/");
- var list = <?php print json_encode($list); ?>;
- document.getElementById('play-mp3').onclick = function (event) {
- var song = list[Math.floor(Math.random()*list.length)];
- niftyplayer('niftyPlayer1').loadAndPlay(path + encodeURIComponent(song));
- document.getElementById('playing').innerHTML=song;
- event.preventDefault();
- return false;
- };
- </script>
- <?php if ($error): ?>
- <div style="display:none;">Error reading path.</div>
- <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement