Disabling webrtc + using nanogong and then wami for record audio see BT#7339

The wav file is transformed in mp3 if the binary  ffmpeg is installed.
1.9.x
Julio Montoya 12 years ago
parent 48d1fab5b9
commit 76b81f8129
  1. 1
      main/document/record_audio.php
  2. 11
      main/document/showinframes.php
  3. 15
      main/inc/lib/display.lib.php
  4. 138
      main/inc/lib/document.lib.php
  5. 46
      main/inc/lib/fileUpload.lib.php
  6. 56
      main/inc/lib/nanogong/upload_nanogong_file.php
  7. 81
      main/inc/lib/wami-recorder/record_document.php
  8. 39
      main/newscorm/learnpath.class.php
  9. 26
      main/newscorm/lp_add_audio.php
  10. 310
      main/template/default/learnpath/record_voice.tpl

@ -168,6 +168,7 @@ function submitVoice() {
//
var applet = document.getElementById("nanogong");
var ret = applet.sendGongRequest( "PostToForm", urlnanogong, "voicefile", cookie, "temp");//'PostToForm', postURL, inputname, cookie, filename
if (ret == null) {
alert(lang_failled_to_submit);
} else {

@ -402,19 +402,14 @@ if ($is_nanogong_available) {
}
//get file from tmp directory
$to_url=api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip;
$to_url = api_get_path(WEB_ARCHIVE_PATH).'temp/audio/'.$file_crip;
echo '<div align="center">';
echo '<a class="btn" href="'.$file_url_web.'" target="_blank">'.get_lang('Download').'</a>';
echo '<br/>';
echo '<br/>';
echo '<applet id="applet" archive="../inc/lib/nanogong/nanogong.jar" code="gong.NanoGong" width="160" height="95">';
echo '<param name="SoundFileURL" value="'.$to_url.'" />';
echo '<param name="ShowSaveButton" value="false" />';
echo '<param name="ShowTime" value="true" />';
echo '<param name="ShowRecordButton" value="false" />';
echo '</applet>';
echo DocumentManager::readNanogongFile($to_url);
//erase temp file in tmp directory when return to documents
$_SESSION['temp_audio_nanogong']=$to_sys;

@ -1571,11 +1571,21 @@ class Display {
return $html;
}
/**
* @param string $file
* @param array $params
* @return null|string
*/
public static function getMediaPlayer($file, $params = array())
{
$fileInfo = pathinfo($file);
switch ($fileInfo['extension']) {
case 'wav':
if (isset($params['url'])) {
return DocumentManager::readNanogongFile($params['url']);
}
break;
case 'mp3':
case 'webm':
$autoplay = null;
@ -1587,14 +1597,13 @@ class Display {
$class = isset($params['class']) ? ' class="'.$params['class'].'"' : null;
$html = '<audio id="'.$id.'" '.$class.' controls '.$autoplay.' '.$width.' src="'.$file.'" >';
$html .= '<object width="'.$params['width'].'" height="50" type="application/x-shockwave-flash" data="'.api_get_path(WEB_LIBRARY_PATH).'javascript/mediaelement/flashmediaelement.swf">
$html .= ' <object width="'.$params['width'].'" height="50" type="application/x-shockwave-flash" data="'.api_get_path(WEB_LIBRARY_PATH).'javascript/mediaelement/flashmediaelement.swf">
<param name="movie" value="'.api_get_path(WEB_LIBRARY_PATH).'javascript/mediaelement/flashmediaelement.swf" />
<param name="flashvars" value="controls=true&file='.$fileInfo['basename'].'" />
</object>';
$html .= '</audio>';
$html .= '</audio>';
return $html;
break;
}
return null;

@ -1113,6 +1113,7 @@ class DocumentManager
*
* @param array $courseInfo
* @param string $path
* @param int $sessionId
* @return int id of document / false if no doc found
*/
public static function get_document_id($courseInfo, $path, $sessionId = null)
@ -3212,7 +3213,7 @@ class DocumentManager
* @param bool When set to true, this runs the indexer without actually saving anything to any database
* @return bool Returns true on presumed success, false on failure
*/
public function index_document(
public static function index_document(
$docid,
$course_code,
$session_id = 0,
@ -3540,4 +3541,139 @@ class DocumentManager
}
}
}
/**
* @param string $file
* @return string
*/
public static function readNanogongFile($file)
{
$nanoGongJarFile = api_get_path(WEB_LIBRARY_PATH).'nanogong/nanogong.jar';
$html = '<applet id="applet" archive="'.$nanoGongJarFile.'" code="gong.NanoGong" width="160" height="95">';
$html .= '<param name="SoundFileURL" value="'.$file.'" />';
$html .= '<param name="ShowSaveButton" value="false" />';
$html .= '<param name="ShowTime" value="true" />';
$html .= '<param name="ShowRecordButton" value="false" />';
$html .= '</applet>';
return $html;
}
/**
* @param string $filePath
* @param string $path
* @param $courseInfo
* @param string $whatIfFileExists overwrite|rename
* @param null $userId
* @param null $groupId
* @param null $toUserId
* @return bool|path
*/
public static function addFileToDocumentTool(
$filePath,
$path,
$courseInfo,
$userId,
$whatIfFileExists = 'overwrite',
$groupId = null,
$toUserId = null
) {
if (!file_exists($filePath)) {
return false;
}
$fileInfo = pathinfo($filePath);
$file = array(
'name' => $fileInfo['basename'],
'tmp_name' => $filePath,
'size' => filesize($filePath),
'from_file' => true
);
$course_dir = $courseInfo['path'].'/document';
$baseWorkDir = api_get_path(SYS_COURSE_PATH).$course_dir;
$filePath = handle_uploaded_document(
$courseInfo,
$file,
$baseWorkDir,
$path,
$userId,
$groupId,
$toUserId,
false,
$whatIfFileExists,
false
);
if ($filePath) {
return DocumentManager::get_document_id($courseInfo, $filePath);
}
return false;
}
/**
* Converts wav to mp3 file.
* Requires the ffmpeg lib. In ubuntu: sudo apt-get install ffmpeg
* @param string $wavFile
* @param bool $removeWavFileIfSuccess
* @return bool
*/
public static function convertWavToMp3($wavFile, $removeWavFileIfSuccess = false)
{
require_once '../../../../vendor/autoload.php';
if (file_exists($wavFile)) {
try {
$ffmpeg = \FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($wavFile);
$mp3File = str_replace('wav', 'mp3', $wavFile);
$result = $video->save(new FFMpeg\Format\Audio\Mp3(), $mp3File);
if ($result && $removeWavFileIfSuccess) {
unlink($wavFile);
}
if (file_exists($mp3File)) {
return $mp3File;
}
} catch (Exception $e) {
}
}
return false;
}
/**
* @param string $documentData
* @param array $courseInfo
* @param string $whatIfFileExists
* @return bool|path
*/
public static function addAndConvertWavToMp3($documentData, $courseInfo, $userId, $whatIfFileExists = 'overwrite')
{
if (empty($documentData)) {
return false;
}
if (isset($documentData['absolute_path']) && file_exists($documentData['absolute_path'])) {
$mp3FilePath = self::convertWavToMp3($documentData['absolute_path']);
//$mp3FilePath = str_replace('wav', 'mp3', $documentData['absolute_path']);
if (!empty($mp3FilePath)) {
$documentId = self::addFileToDocumentTool(
$mp3FilePath,
dirname($documentData['path']),
$courseInfo,
$userId,
$whatIfFileExists
);
if (!empty($documentId)) {
return $documentId;
}
}
}
return false;
}
}

@ -191,6 +191,7 @@ function handle_uploaded_document(
if (!$user_id) {
die('Not a valid user.');
}
// Strip slashes
$uploaded_file['name'] = stripslashes($uploaded_file['name']);
// Add extension to files without one (if possible)
@ -236,8 +237,10 @@ function handle_uploaded_document(
$upload_path = $upload_path.'/';
}
$file_path = $upload_path.$clean_name;
// Full path to where we want to store the file with trailing slash
$where_to_save = $base_work_dir.$upload_path;
// At least if the directory doesn't exist, tell so
if (!is_dir($where_to_save)) {
if ($output){
@ -261,8 +264,9 @@ function handle_uploaded_document(
case 'overwrite':
// Check if the target file exists, so we can give another message
$file_exists = file_exists($store_path);
if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) {
if (moveUploadedFile($uploaded_file, $store_path)) {
chmod($store_path, $files_perm);
if ($file_exists) {
// UPDATE DATABASE
$document_id = DocumentManager::get_document_id($_course, $file_path);
@ -327,7 +331,7 @@ function handle_uploaded_document(
$store_path = $where_to_save.$new_name;
$new_file_path = $upload_path.$new_name;
if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) {
if (moveUploadedFile($uploaded_file, $store_path)) {
chmod($store_path, $files_perm);
@ -355,15 +359,14 @@ function handle_uploaded_document(
return false;
}
break;
// Only save the file if it doesn't exist or warn user if it does exist
default:
// Only save the file if it doesn't exist or warn user if it does exist
if (file_exists($store_path)) {
if ($output) {
Display::display_error_message($clean_name.' '.get_lang('UplAlreadyExists'));
}
} else {
if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) {
if (moveUploadedFile($uploaded_file, $store_path)) {
chmod($store_path, $files_perm);
// Put the document data in the database
@ -396,6 +399,21 @@ function handle_uploaded_document(
}
}
/**
* @param string $file
* @param string $storePath
* @return bool
*/
function moveUploadedFile($file, $storePath)
{
$handleFromFile = isset($file['from_file']) && $file['from_file'] ? true : false;
if ($handleFromFile) {
return file_exists($file['tmp_name']);
} else {
return move_uploaded_file($file['tmp_name'], $storePath);
}
}
/**
* Checks if there is enough place to add a file on a directory
* on the base of a maximum directory size allowed
@ -703,7 +721,6 @@ function unzip_uploaded_file($uploaded_file, $upload_path, $base_work_dir, $max_
closedir($dir);
} else {
error_log('Could not create directory '.$base_work_dir.$upload_path.' to unzip files');
}
chdir($save_dir); // Back to previous dir position
}
@ -870,10 +887,25 @@ function filter_extension(&$filename) {
* @param string $filetype
* @param int $filesize
* @param string $title
* @param string $comment
* @param int $readonly
* @param bool $save_visibility
* @param int $group_id
* @param int $session_id Session ID, if any
* @return id if inserted document
*/
function add_document($_course, $path, $filetype, $filesize, $title, $comment = null, $readonly = 0, $save_visibility = true, $group_id = null, $session_id = 0) {
function add_document(
$_course,
$path,
$filetype,
$filesize,
$title,
$comment = null,
$readonly = 0,
$save_visibility = true,
$group_id = null,
$session_id = 0
) {
if (empty($session_id)) {
$session_id = api_get_session_id();
}

@ -0,0 +1,56 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file allows creating new svg and png documents with an online editor.
*
* @package chamilo.document
*
* @author Juan Carlos Raña Trabado
* @since 5/mar/2011
*/
/**
* Code
*/
require_once '../../../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
api_protect_course_script();
api_block_anonymous_users();
if (!isset($_GET['filename']) || !isset($_GET['file_field'])) {
api_not_allowed(false);
exit;
}
$courseInfo = api_get_course_info();
$fileUpload = null;
if (is_uploaded_file($_FILES[$_GET['file_field']]['tmp_name'])) {
$fileUpload = $_FILES[$_GET['file_field']];
} else {
exit;
}
$output = false;
$documentData = DocumentManager::upload_document($_FILES, $_GET['path'], null, null, 0, 'overwrite', false, $output);
if (!empty($documentData)) {
$newDocId = $documentData['id'];
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3($documentData, $courseInfo, api_get_user_id());
if ($newMp3DocumentId) {
$newDocId = $newMp3DocumentId;
}
if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
$lpItemId = $_REQUEST['lp_item_id'];
/** @var learnpath $lp */
$lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null;
if (!empty($lp)) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
}
}
}

@ -72,54 +72,39 @@ $fh = fopen($documentPath, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
$addToLP = false;
if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
$lpItemId = $_REQUEST['lp_item_id'];
$lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null;
if (!empty($lp)) {
$addToLP = true;
// Converts wav into mp3
require_once '../../../../vendor/autoload.php';
$ffmpeg = \FFMpeg\FFMpeg::create();
$oldWavFile = $documentPath;
if (file_exists($oldWavFile)) {
$video = $ffmpeg->open($oldWavFile);
$waminame_to_save = str_replace('wav', 'mp3', $waminame_to_save);
$documentPath = $saveDir.'/'.$waminame_to_save;
$title_to_save = $waminame_to_save;
//$video->save(new \FFMpeg\Format\Audio\Vorbis());
$result = $video->save(new FFMpeg\Format\Audio\Mp3(), $documentPath);
if ($result) {
unlink($oldWavFile);
}
}
}
}
if (file_exists($documentPath)) {
// Add document to database
$newDocId = add_document($_course, $wamidir.'/'.$waminame_to_save, 'file', filesize($documentPath), $title_to_save);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$newDocId,
'DocumentAdded',
api_get_user_id(),
$groupId,
null,
null,
null,
$current_session_id
);
if ($addToLP) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
$fileInfo = pathinfo($documentPath);
$courseInfo = api_get_course_info();
$file = array(
'file' => array(
'name' => $fileInfo['basename'],
'tmp_name' => $documentPath,
'size' => filesize($documentPath),
'from_file' => true
)
);
$output = true;
$documentData = DocumentManager::upload_document($file, $wamidir, null, null, 0, 'overwrite', false, $output);
if (!empty($documentData)) {
$newDocId = $documentData['id'];
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3($documentData, $courseInfo, api_get_user_id());
if ($newMp3DocumentId) {
$newDocId = $newMp3DocumentId;
}
}
if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
$lpItemId = $_REQUEST['lp_item_id'];
/** @var learnpath $lp */
$lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null;
if (!empty($lp)) {
$lp->set_modified_on();
$lpItem = new learnpathItem($lpItemId);
$lpItem->add_audio_from_documents($newDocId);
}
}
}

@ -2080,13 +2080,23 @@ class learnpath
$audio = $row['audio'];
$file = '../../courses/'.$courseInfo['path'].'/document/audio/'.$audio;
$file = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio;
$url = api_get_path(WEB_COURSE_PATH).$courseInfo['path'].'/document/audio/'.$audio;
if (!file_exists($file)) {
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$file = '../../courses/'.$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
}
$player = Display::getMediaPlayer($file, array('id' => 'lp_audio_media_player', 'autoplay' => $autostart_audio, 'width' => '100%'));
$file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
$url = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$audio;
}
$player = Display::getMediaPlayer(
$file,
array(
'id' => 'lp_audio_media_player',
'url' => $url,
'autoplay' => $autostart_audio,
'width' => '100%'
)
);
// The mp3 player.
$output = '<div id="container">';
@ -2317,7 +2327,13 @@ class learnpath
}
}
public function get_preview_image_path($size = null, $path_type = 'web') {
/**
* @param string $size
* @param string $path_type
* @return bool|string
*/
public function get_preview_image_path($size = null, $path_type = 'web')
{
$preview_image = $this->get_preview_image();
if (isset($preview_image) && !empty($preview_image)) {
$image_sys_path = api_get_path(SYS_COURSE_PATH).$this->course_info['path'].'/upload/learning_path/images/';
@ -4211,7 +4227,8 @@ class learnpath
* @param string Optional string giving the new image of this learnpath
* @return bool Returns true if theme name is not empty
*/
public function set_preview_image($name = '') {
public function set_preview_image($name = '')
{
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
error_log('New LP - In learnpath::set_preview_image()', 0);
@ -4224,7 +4241,7 @@ class learnpath
if ($this->debug > 2) {
error_log('New LP - lp updated with new preview image : ' . $this->preview_image, 0);
}
$res = Database::query($sql);
Database::query($sql);
return true;
}
@ -4250,7 +4267,7 @@ class learnpath
}
/**
* Sets the hide_toc_frame parameter of a LP (and save)
* @param int 1 if frame is hiddent 0 thenelse
* @param int 1 if frame is hidden 0 then else
* @return bool Returns true if author's name is not empty
*/
public function set_hide_toc_frame($hide) {
@ -5061,7 +5078,8 @@ class learnpath
if ($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module' && $arrLP[$i]['item_type'] != 'dir') {
$audio .= '<input type="file" name="mp3file' . $arrLP[$i]['id'] . '" id="mp3file" />';
if (!empty ($arrLP[$i]['audio'])) {
$audio .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<br /><input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
$audio .= '<br />'.Security::remove_XSS($arrLP[$i]['audio']).'<br />
<input type="checkbox" name="removemp3' . $arrLP[$i]['id'] . '" id="checkbox' . $arrLP[$i]['id'] . '" />' . get_lang('RemoveAudio');
}
}
}
@ -5165,7 +5183,6 @@ class learnpath
}
$return .= '<div class="lp_tree well">';
$return .= '<ul id="lp_item_list">';
$return .='<h4>'.$this->name.'</h4><br>';

@ -22,7 +22,6 @@ $isStudentView = (int) $_REQUEST['isStudentView'];
$learnpath_id = (int) $_REQUEST['lp_id'];
$submit = $_POST['submit_button'];
$type = isset($_GET['type']) ? $_GET['type'] : null;
$action = isset($_GET['action']) ? $_GET['action'] : null;
@ -82,13 +81,16 @@ $tpl = new Template($tool_name);
$form = new FormValidator('add_audio', 'post', api_get_self().'?action=add_audio&id='.$lp_item_id, null, array('enctype' => 'multipart/form-data'));
$suredel = trim(get_lang('AreYouSureToDelete'));
$file = null;
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$file = null;
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
$file = '../../courses/'.$_course['path'].'/document/audio/'.$lp_item->audio;
$file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/audio/'.$lp_item->audio;
if (!file_exists($file)) {
$file = '../../courses/'.$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
$file = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
$urlFile = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$lpPathInfo['dir'].$lp_item->audio;
}
}
@ -101,16 +103,26 @@ $page .= $_SESSION['oLP']->return_new_tree(null, true);
$page .= '</div>';
$page .= '<div id="doc_form" class="span8">';
$form->addElement('header', get_lang('RecordYourVoice'));
$tpl->assign('unique_file_id', api_get_unique_id());
$tpl->assign('course_code', api_get_course_id());
$tpl->assign('php_session_id', session_id());
$tpl->assign('filename', $lp_item->get_title().'_nano.wav');
$tpl->assign('enable_nanogong', api_get_setting('enable_nanogong') == 'true' ? 1 : 0);
$tpl->assign('enable_wami', api_get_setting('enable_wami_record') == 'true' ? 1 : 0);
//$tpl->assign('cur_dir_path', api_remove_trailing_slash($lpPathInfo['dir']));
$tpl->assign('cur_dir_path', '/audio');
$tpl->assign('lp_item_id', $lp_item_id);
$tpl->assign('lp_dir', api_remove_trailing_slash($lpPathInfo['dir']));
$voiceContent = $tpl->fetch('default/learnpath/record_voice.tpl');
$form->addElement('html', $voiceContent);
$form->addElement('header', get_lang('UplUpload'));
$form->addElement('html', $lp_item->get_title());
$form->addElement('file', 'file', get_lang('AudioFile'), 'style="width: 250px"');
if (!empty($file)) {
@ -121,7 +133,7 @@ if (!empty($file)) {
$form->addElement('hidden', 'id', $lp_item_id);
if (!empty($file)) {
$audioPlayer = '<div id="preview">'.Display::getMediaPlayer($file)."</div>";
$audioPlayer = '<div id="preview">'.Display::getMediaPlayer($file, array('url' => $urlFile))."</div>";
$form->addElement('label', get_lang('Preview'), $audioPlayer);
}
$form->addElement('button', 'submit', get_lang('Edit'));

@ -21,15 +21,91 @@
</div>
</div>
<div id="nanogong">
<applet id="nanogongApplet" archive="{{ _p.web_lib }}nanogong/nanogong.jar" code="gong.NanoGong" width="250" height="95">
<param name="ShowTime" value="true" />
<param name="AudioFormat" value="ImaADPCM" />
</applet>
<form name="form_nanogong">
<input id="status" type="hidden" name="status" value="0">
<button class="upload" type="submit" value="{{ 'Send' | get_lang }}" onclick="submitVoice()">
{{ 'Send' | get_lang }}
</button>
</form>
<span id="nanogong_result" ></span>
</div>
<script>
function checkNanoGongEnable() {
var nanogongEnabled = {{ enable_nanogong }};
if (nanogongEnabled != 1) {
return false;
}
return recorder = document.getElementById("nanogongApplet");
}
function checkWamiEnable() {
var wamiEnabled = {{ enable_wami }};
if (wamiEnabled != 1) {
return false;
}
if (swfobject.hasFlashPlayerVersion("1")) {
return true;
} else {
return false;
}
}
function submitVoice() {
// lang vars
var lang_no_applet = "{{ 'NanogongNoApplet' | get_lang }}";
var lang_record_before_save = "{{ 'NanogongRecordBeforeSave' | get_lang }}";
var lang_give_a_title = "{{ 'NanogongGiveTitle' | get_lang }}";
var lang_failled_to_submit = "{{ 'NanogongFailledToSubmit' | get_lang }}";
var lang_submitted = "{{'NanogongSubmitted' | get_lang }}";
// user and group id
//path, url and filename
var filename = "{{ filename }}"; //adding name file, tag and extension
var filename = encodeURIComponent(filename);
var fileInput = 'file';
var urlNanoGong = "{{ _p.web_lib }}nanogong/upload_nanogong_file.php?lp_item_id={{ lp_item_id }}&filename="+filename+"&file_field="+fileInput+"&cidReq={{ course_code }}&path={{ cur_dir_path }}";
var cookie= "ch_sid=" + "{{ php_session_id }}";
// Check
var recorder;
if (!(recorder = document.getElementById("nanogongApplet"))) {
alert(lang_no_applet);
return
}
var duration = parseInt(recorder.sendGongRequest("GetMediaDuration", "audio")) || 0
if (duration <= 0) {
alert(lang_record_before_save);
return;
}
var ret = recorder.sendGongRequest("PostToForm", urlNanoGong, fileInput, cookie, filename);
if (ret == null) {
alert(lang_failled_to_submit);
} else {
alert(lang_submitted);
$("#status").attr('value', '1');
}
}
function setupRecorder() {
$('#wami-recorder').css('margin-bottom', '150px');
Wami.setup({
id : "wami",
onReady : setupGUI,
swfUrl : "{{ _p.web_lib }}wami-recorder/Wami.swf"
});
$('#wami-recorder').css('margin-bottom', '150px');
}
function setupGUI() {
@ -37,9 +113,9 @@ function setupGUI() {
var gui = new Wami.GUI({
id : "wami-recorder",
singleButton : true,
recordUrl : "{{ _p.web_lib }}wami-recorder/record_document.php?lp_item_id={{ lp_item_id }}&waminame="+uniq+"&wamidir={{ lp_dir }}&wamiuserid={{ _u.user_id }}",
recordUrl : "{{ _p.web_lib }}wami-recorder/record_document.php?lp_item_id={{ lp_item_id }}&waminame="+uniq+"&wamidir={{ cur_dir_path }}&wamiuserid={{ _u.user_id }}",
buttonUrl : "{{ _p.web_lib }}wami-recorder/buttons.png",
buttonNoUrl: "{{ _p.web_img }}blank.gif",
buttonNoUrl : "{{ _p.web_img }}blank.gif",
onRecordStart : function() {
$('#start-recording').show();
},
@ -53,134 +129,136 @@ function setupGUI() {
gui.setPlayEnabled(true);
}
</script>
<script>
$(document).ready(function() {
var isChrome = navigator.webkitGetUserMedia;
isChrome = false;
if (isChrome) {
$('#rtc').show();
$('#wami').hide();
} else {
$('#rtc').hide();
$('#wami').show();
var recordWami = $('#record-wami');
recordWami.on('click', function() {
setupRecorder();
return false;
});
}
var format = 'webm'; // or wav
var record = $('#record');
var stop = document.getElementById('stop');
var preview = document.getElementById('audio');
var progressInfo = document.getElementById('progress-info');
var previewBlock = document.getElementById('preview');
function postBlob(blob, fileType, fileName) {
// FormData
var formData = new FormData();
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);
// progress-bar
var hr = document.createElement('hr');
progressInfo.appendChild(hr);
var strong = document.createElement('strong');
strong.innerHTML = fileType + ' upload progress: ';
progressInfo.appendChild(strong);
var progress = document.createElement('progress');
progressInfo.appendChild(progress);
// POST the Blob
$.ajax({
url:'{{ _p.web_ajax }}lp.ajax.php?a=record_audio&lp_item_id={{ lp_item_id }}',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success:function(fileURL) {
window.location.reload();
progressInfo.appendChild(document.createElement('hr'));
var mediaElement = document.createElement(fileType);
mediaElement.src = fileURL;
mediaElement.controls = true;
var uniq = 'id' + (new Date()).getTime();
mediaElement.id = uniq;
$(previewBlock).html('');
previewBlock.appendChild(mediaElement);
mediaElement.play();
$(progressInfo).html('');
window.location.reload();
}
});
}
var recordAudio, recordVideo;
record.on('click', function() {
var rtcEnabled = false;
$(document).ready(function() {
var isChrome = navigator.webkitGetUserMedia;
$('#rtc').hide();
$('#wami').hide();
$('#nanogong').hide();
if (rtcEnabled && isChrome) {
$('#rtc').show();
} else if (checkNanoGongEnable()) {
$('#nanogong').show();
} else if (checkWamiEnable()) {
$('#wami').show();
var recordWami = $('#record-wami');
recordWami.on('click', function() {
setupRecorder();
return false;
});
} else {
// Nothing
}
// Start web RTC code
var format = 'webm'; // or wav
var record = $('#record');
var stop = document.getElementById('stop');
var preview = document.getElementById('audio');
var progressInfo = document.getElementById('progress-info');
var previewBlock = document.getElementById('preview');
function postBlob(blob, fileType, fileName) {
// FormData
var formData = new FormData();
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);
// progress-bar
var hr = document.createElement('hr');
progressInfo.appendChild(hr);
var strong = document.createElement('strong');
strong.innerHTML = fileType + ' upload progress: ';
progressInfo.appendChild(strong);
var progress = document.createElement('progress');
progressInfo.appendChild(progress);
// POST the Blob
$.ajax({
url:'{{ _p.web_ajax }}lp.ajax.php?a=record_audio&lp_item_id={{ lp_item_id }}',
data: formData,
processData: false,
contentType: false,
type: 'POST',
success:function(fileURL) {
window.location.reload();
progressInfo.appendChild(document.createElement('hr'));
var mediaElement = document.createElement(fileType);
mediaElement.src = fileURL;
mediaElement.controls = true;
var uniq = 'id' + (new Date()).getTime();
mediaElement.id = uniq;
$(previewBlock).html('');
previewBlock.appendChild(mediaElement);
mediaElement.play();
$(progressInfo).html('');
window.location.reload();
}
});
}
record.disabled = true;
var recordAudio, recordVideo;
var myURL = (window.URL || window.webkitURL || {});
record.on('click', function() {
record.disabled = true;
if (navigator.getUserMedia) {
var myURL = (window.URL || window.webkitURL || {});
navigator.getUserMedia({
audio: true,
video: false
},
function(stream) {
if (window.IsChrome) stream = new window.MediaStream(stream.getAudioTracks());
if (navigator.getUserMedia) {
preview.src = myURL.createObjectURL(stream);
console.log(preview.src);
preview.play();
navigator.getUserMedia({
audio: true,
video: false
},
function(stream) {
if (window.IsChrome) stream = new window.MediaStream(stream.getAudioTracks());
recordAudio = RecordRTC(stream, {
type: 'audio'
});
recordAudio.startRecording();
preview.src = myURL.createObjectURL(stream);
console.log(preview.src);
preview.play();
/*recordVideo = RecordRTC(stream, {
type: 'video'
});*/
//recordVideo.startRecording();
stop.disabled = false;
},
function(err) {
console.log("The following error occured: " + err);
return false;
recordAudio = RecordRTC(stream, {
type: 'audio'
});
}
});
recordAudio.startRecording();
/*recordVideo = RecordRTC(stream, {
type: 'video'
});*/
//recordVideo.startRecording();
stop.disabled = false;
},
function(err) {
console.log("The following error occured: " + err);
return false;
});
}
});
stop.onclick = function() {
record.disabled = false;
stop.disabled = true;
stop.onclick = function() {
record.disabled = false;
stop.disabled = true;
var fileName = Math.round(Math.random() * 99999999) + 99999999;
var fileName = Math.round(Math.random() * 99999999) + 99999999;
recordAudio.stopRecording();
recordAudio.stopRecording();
postBlob(recordAudio.getBlob(), 'audio', fileName + '.' + format);
postBlob(recordAudio.getBlob(), 'audio', fileName + '.' + format);
//recordVideo.stopRecording();
//PostBlob(recordVideo.getBlob(), 'video', fileName + '.webm');
//recordVideo.stopRecording();
//PostBlob(recordVideo.getBlob(), 'video', fileName + '.webm');
preview.src = '';
};
preview.src = '';
};
});
// End web RTC code
});
</script>

Loading…
Cancel
Save