Exemplo n.º 1
0
function scanForSounds($path)
{
    // Set up a return value
    $return = '';
    // Set up to save files
    $files = array();
    $dirs = array();
    // Open up the directory
    if ($handle = opendir($path)) {
        while (($file = readdir($handle)) !== false) {
            // Skip anything hidden
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            // If it's not a .wav, skip on
            if (substr($file, -4) != '.wav') {
                continue;
            }
            $fullpath = "{$path}/{$file}";
            if (is_dir($fullpath)) {
                $dirs[] = $fullpath;
            } else {
                // Store for handling!
                $files[] = $file;
            }
            // if (is_dir($file))
        }
        // while (($file = readdir($handle)) !== false)
        // Sort the file listing for cleanness sake
        asort($files);
        foreach ($files as $f) {
            // Get a clean name for the title later
            $basename = basename($f, '.wav');
            // Use that to make a clean-ish ID
            $elem_id = preg_replace('/\\s+/', '_', strtolower($basename));
            // Build a couple of paths
            $oggpath = "{$path}/{$basename}.ogg";
            $mp3path = "{$path}/{$basename}.mp3";
            $wavpath = "{$path}/{$basename}.wav";
            $aifpath = "{$path}/{$basename}.aif";
            // Set it up as a full-on audio object
            //$return .= "<audio id=\"sound_$elem_id\" title=\"$basename\" src=\"$wavpath\" autobuffer><!--<source src=\"$aifpath\" type=\"audio/x-aiff\"><source src=\"$wavpath\" type=\"audio/x-wav\">--></audio>\n";
            $return .= "<audio id=\"sound_{$elem_id}\" title=\"{$basename}\" autobuffer><source src=\"{$wavpath}\" type=\"audio/x-wav\"><source src=\"{$oggpath}\" type=\"application/ogg\"><source src=\"{$mp3path}\" type=\"audio/mpeg\"></audio>\n";
        }
        // foreach ($files as $f)
        asort($dirs);
        foreach ($dirs as $d) {
            // Scan the path, add it in
            $return .= scanForSounds($d);
        }
        // foreach ($dirs as $d)
    }
    // if ($handle = opendir($path))
    // Hand it back
    return $return;
}
Exemplo n.º 2
0
function scanForSounds($path)
{
    // Set up a return value
    $return = '';
    // Open up the directory
    if ($handle = opendir($path)) {
        // Start it up
        $return = '<ul>';
        while (($file = readdir($handle)) !== false) {
            // Skip anything hidden
            if (substr($file, 0, 1) == '.') {
                continue;
            }
            $fullpath = "{$path}/{$file}";
            $soundid = basename($file, '.wav');
            if (is_dir($fullpath)) {
                // Note it
                $return .= "<li class=\"dir\">{$fullpath}";
                // Scan this path, add it in
                $return .= scanForSounds($fullpath);
                // Wrap it up
                $return .= '</li>';
            } else {
                // If it's not a .wav, skip on
                if (substr($file, -4) != '.wav') {
                    continue;
                }
                // Set it up as a full-on audio object
                $return .= "<li class=\"sound\"><span>{$fullpath}:</span> <audio id=\"{$soundid}\" src=\"{$fullpath}\" autoload controls></li>";
            }
            // if (is_dir($file))
        }
        // while (($file = readdir($handle)) !== false)
        // Close it up
        $return .= '</ul>';
    } else {
        $return = "<span class=\"error\">Unable to open \"{$path}\"</span>";
    }
    // if ($handle = opendir($path))
    // Hand it back
    return $return;
}