function get_mp3duration($attachment) { require_once VIVVO_FS_INSTALL_ROOT . 'lib/zedwood/mp3file.php'; $mp3 = new mp3file($filename = VIVVO_FS_ROOT . VIVVO_FS_FILES_DIR . $attachment->real_path); $metadata = $mp3->get_metadata(); if (isset($metadata['Length'])) { return $metadata['Length']; } else { return ceil(filesize($filename) / 60000000); // 128kbps, stereo } }
if (!($voiceshadow = $DB->get_record("voiceshadow", array("id" => $a)))) { error("Course module is incorrect"); } if (!($course = $DB->get_record("course", array("id" => $voiceshadow->course)))) { error("Course is misconfigured"); } if (!($cm = get_coursemodule_from_instance("voiceshadow", $voiceshadow->id, $course->id))) { error("Course Module ID was incorrect"); } } $name = "var{$var}"; $linktofile = $CFG->wwwroot . '/mod/voiceshadow/file.php?file=' . $voiceshadow->{$name}; $file = voiceshadow_getfileid($voiceshadow->{$name}); $AF = new AudioFile(); if (is_file($file->fullpatch)) { $AF->loadFile($file->fullpatch); $duration = round($AF->wave_length); if (empty($duration)) { $m = new mp3file($file->fullpatch); $a = $m->get_metadata(); $duration = $a['Length']; } } if ($uid) { $USER = $DB->get_record("user", array("id" => $uid)); } if (empty($time)) { $time = time(); } $json = array("play" => $linktofile, "title" => $voiceshadow->name, "descr" => strip_tags($voiceshadow->intro), "type" => 'voiceshadow', "id" => $id, "cid" => $course->id, "uid" => $USER->id, "filename" => str_replace(" ", "_", $USER->username) . "_" . date("Ymd_Hi", $time), "duration" => $duration); echo json_encode($json);
$name = preg_replace("/[^A-Z0-9._-]/i", "_", $audio_name . "." . $extension); // if directory doesn't exist attempt to create it if (!file_exists(UPLOAD_DIR)) { mkdir(UPLOAD_DIR, 0700); } //stores the file location...relative directory $fileLocation = UPLOAD_DIR . $name; print_r($fileLocation); // try to move the file to the proper directory $success = move_uploaded_file($audioFile["tmp_name"], $fileLocation); // if unsucessful print error and exit if (!$success) { echo "<p> unable to save file. </p>"; exit; } else { $mp3Info = new mp3file($fileLocation); $mp3Data = $mp3Info->get_metadata(); $mp3Duration = $mp3Info->getDuration($mp3Data, 0); $length = $mp3Data['Length mm:ss']; // set permissions on the new file chmod(UPLOAD_DIR . $name, 0644); // add user's audio to db $query = 'CALL audio_add("' . $audio_name . '","' . $extension . '","' . $bitrate . '","' . $tempo . '","' . $size . '","' . $length . '","' . $genre . '","' . $price . '","' . $member_id . '"' . ')'; $result = $db->query($query); } } // no error found } else { $error_flag++; echo "<p> Wrong file </p>"; echo $_FILES["audiofile"]["error"] . " " . $_FILES["audiofile"]["type"];
public static function samplelookup(&$mp3) { //bits MPEG1 MPEG2 MPEG2.5 $array = array(); $array['00'] = array('44100', '22050', '11025'); $array['01'] = array('48000', '24000', '12000'); $array['10'] = array('32000', '16000', '8000'); $array['11'] = array('res', 'res', 'res'); $whichcolumn = -1; if (mp3file::is_mpeg10($mp3)) { $whichcolumn = 0; } else { if (mp3file::is_mpeg20($mp3)) { $whichcolumn = 1; } else { if (mp3file::is_mpeg25($mp3)) { $whichcolumn = 2; } } } if (isset($array[$mp3['Sampling Freq Idx']][$whichcolumn])) { return $array[$mp3['Sampling Freq Idx']][$whichcolumn]; } else { return 'unknown'; } }