_officialdave

Cache Free Playback Nifty Audio Player

Jul 15th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.91 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3.  
  4.     /********************************************************************************/
  5.     /*                                      *****************************************/
  6.     /* auto.php for Nifty Audio Player      *****************************************/
  7.     /* portions by http://digicave.org      *****************************************/
  8.     /* v.02 11/23/2008                      *****************************************/
  9.     /*                                      *****************************************/
  10.     /********************************************************************************/
  11.  
  12. $file_dir   =   "media";        //change this to a folder name
  13. $omit_chars =   0;          //how many characters to cut off the title's front
  14. $target     =   $file_dir;
  15.  
  16.     /********************************************************************************/
  17.     /*                                      *****************************************/
  18.     /* CACHE PREVENTION DURING PLAYBACK     *****************************************/
  19.     /*                                      *****************************************/
  20.     /********************************************************************************/
  21.  
  22.     if (isset($_GET['nocache'])) {
  23.         $fileonly   =   stripslashes($_GET['param']);
  24.         $file       =   $target.'/'.$fileonly;
  25.         $fh     =   fopen($file,"rb");
  26.         while (!feof($fh))
  27.             {
  28.             header("Cache-Control: no-store, must-revalidate");
  29.             header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  30.             header("Content-Type: audio/mpeg");
  31.             header('Content-Length: ' . filesize($file));
  32.             print(fread($fh, (1*(1024*1024))));
  33.             }
  34.         fclose($fh);
  35.     } else {
  36.  
  37. print '
  38. <?xml version="1.0" encoding="utf-8"?>
  39. <!--  PROPERTY FORMAT LEGEND:  -->
  40. <!--Rectangle: topColor,bottomColor,fillAlpha,cornerRadius,strokeColor,strokeAlpha,strokeWidth-->
  41. <!--Text: font,color,alpha,size,bold-->
  42. <!--Simple Property: color,alpha-->
  43. <music
  44. playerMode="1"
  45. displayTimeInfo="true"
  46. playerWidth="350"
  47. playerHeight="35"
  48. playerX="20"
  49. playerY="10"
  50. flyOut="bottom"
  51. autoStart="true"
  52. buttonSize="25"
  53. buttonPadding="5"
  54. buttonY="5"
  55. playInSequence="true"
  56. playerVolume="100"
  57. embedFonts="false"
  58. playerBg="282828,000000,100,5,171717,100,1"
  59. playerBgShine="FFFFFF,FFFFFF,10,5,333333,0,1"
  60. buttonBg="444444,000000,100,7,000000,100,1"
  61. buttonInnerStroke="363636,000000,100,7,333333,100,1"
  62. buttonBgHover="0D97F2,075d99,100,7,064B79,100,1"
  63. buttonIcon="888888,100"
  64. buttonIconHover="FFFFFF,100"
  65.  
  66. displaySongText="Verdana,A4A4A4,100,10,false"
  67. displaySongTimeTotal="Arial,A4A4A4,100,10,false"
  68. displaySongTimeElapsed="Arial,FFFFFF,100,10,true"
  69. displaySongTextY="2"
  70. displaySongTimeY="2"
  71. pauseDisplayFor="2"
  72. songTitleScrollTime="3"
  73. sliderHeight="5"
  74. sliderY="21"
  75. sliderButtonWidth="10"
  76. sliderButtonHeight="10"
  77. sliderBg="000000,333333,100,3,0,0,0"
  78. sliderFill="0D97F2,075d99,100,3,0,0,0"
  79. sliderStramProgress="333333,444444,100,3,0,0,0"
  80. sliderButton="FFFFFF,666666,100,10,333333,100,1"
  81. volumeHeight="70"
  82. volumeBg="222222,000000,100,9,333333,100,1"
  83. volumeSliderBg="333333,444444,100,3,0,0,0"
  84. volumeSliderFill="0D97F2,075d99,100,3,0,0,0"
  85. volumeText="Arial,FFFFFF,100,10,false"
  86. volumeSliderButton="FFFFFF,666666,100,9,333333,100,1"
  87.  
  88. listOpen="true"
  89. listHeight="180"
  90. listPadding="10"
  91. listScrollbarWidth="9"
  92. listBg="222222,000000,100,15,333333,100,1"
  93. listScrollbar="666666,100"
  94. listScrollbarBg="000000,100"
  95. listItemHeight="20"
  96. listItemBg="333333,100"
  97. listItemBgActive="075d99,100"
  98. listTitleText="Verdana,999999,100,10,false"
  99. listTitleTextActive="Verdana,FFFFFF,100,10,false"
  100. listTitleScrollTime="5"
  101. ><group>'."\n";
  102.  
  103. clearstatcache();
  104.  
  105. $sourcepath = $file_dir;
  106.  
  107. // Replace \ by / and remove the final / if any
  108. $root = ereg_replace( "/$", "", ereg_replace( "[\\]", "/", $sourcepath ));
  109.  
  110. // Search for mp3 files
  111. $results = m_find_in_dir( $root, ".*\.mp3" );
  112. if( false === $results ) {
  113.     echo "'{$sourcepath}' is not a valid directory\n";
  114. } else {
  115.  
  116.             $xml_string= array();
  117.            
  118.             foreach ($results AS $file)
  119.                 {
  120.                 $file = substr($file, strlen($file_dir)+1);
  121.                 $filer = $_SERVER["SCRIPT_NAME"];
  122.                 $break = explode('/', $filer);
  123.                 $pfile = $break[count($break) - 1];
  124.                
  125.                 // If you require your filenames to include _underscores, uncomment the next line
  126.                 //$file = str_replace(" ", "_", $file);
  127.                
  128.                 $urlHurl = $pfile."?nocache&amp;param=".rawurlencode($file);
  129.                
  130.             if(substr($file, -3) == "mp3")
  131.                 {
  132.                 // remove directory info from filename for display
  133.                 $file = preg_replace( '/^.+\/(.+)/', '$1', $file);
  134.                 $tmp_str = '<song title="'.substr(str_replace("_", " ", $file), $omit_chars, -4).'" file="'.$urlHurl.'" />'."\n";
  135.                 array_push($xml_string, $tmp_str);
  136.             }
  137.                    
  138.                
  139.             }
  140.            
  141.             sort($xml_string);
  142.             $xml_count = count($xml_string);
  143.             for($i=0; $i<$xml_count; $i++)
  144.                 {
  145.             print $xml_string[$i];
  146.             }
  147.             print '</group></music>';
  148.            
  149. }
  150.  
  151.  
  152.  
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. /**
  161.  * Search for a file maching a regular expression
  162.  *
  163.  * @param string $root Root path
  164.  * @param string $pattern POSIX regular expression pattern
  165.  * @param boolean $recursive Set to true to walk the subdirectories recursively
  166.  * @param boolean $case_sensitive Set to true for case sensitive search
  167.  * @return array An array of string representing the path of the matching files, or false in case of error
  168.  */
  169. function m_find_in_dir( $root, $pattern, $recursive = true, $case_sensitive = false ) {
  170.     $result = array();
  171.     if( $case_sensitive ) {
  172.         if( false === m_find_in_dir__( $root, $pattern, $recursive, $result )) {
  173.             return false;
  174.         }
  175.     } else {
  176.         if( false === m_find_in_dir_i__( $root, $pattern, $recursive, $result )) {
  177.             return false;
  178.         }
  179.     }
  180.    
  181.     return $result;
  182. }
  183.  
  184. /**
  185.  * @access private
  186.  */
  187. function m_find_in_dir__( $root, $pattern, $recursive, &$result ) {
  188.     $dh = @opendir( $root );
  189.     if( false === $dh ) {
  190.         return false;
  191.     }
  192.     while( $file = readdir( $dh )) {
  193.         if( "." == $file || ".." == $file ){
  194.             continue;
  195.         }
  196.         if( false !== @ereg( $pattern, "{$root}/{$file}" )) {
  197.             $result[] = "{$root}/{$file}";
  198.         }
  199.         if( false !== $recursive && is_dir( "{$root}/{$file}" )) {
  200.             m_find_in_dir__( "{$root}/{$file}", $pattern, $recursive, $result );
  201.         }
  202.     }
  203.     closedir( $dh );
  204.     return true;
  205. }
  206.  
  207. /**
  208.  * @access private
  209.  */
  210. function m_find_in_dir_i__( $root, $pattern, $recursive, &$result ) {
  211.     $dh = @opendir( $root );
  212.     if( false === $dh ) {
  213.         return false;
  214.     }
  215.     while( $file = readdir( $dh )) {
  216.         if( "." == $file || ".." == $file ){
  217.             continue;
  218.         }
  219.         if( false !== @eregi( $pattern, "{$root}/{$file}" )) {
  220.             $result[] = "{$root}/{$file}";
  221.         }
  222.         if( false !== $recursive && is_dir( "{$root}/{$file}" )) {
  223.             m_find_in_dir__( "{$root}/{$file}", $pattern, $recursive, $result );
  224.         }
  225.     }
  226.     closedir( $dh );
  227.     return true;
  228. }
  229. ?>
Add Comment
Please, Sign In to add comment