我是Wami Recorder的新手,我从来没有使用Flash,所以这实际上可能是一个愚蠢的问题。
基本上,如何实施Wami Recorder?我在网站上看过它,它在那里工作得很好,但是当我下载它并尝试在localhost中使用它作为Xampp的一部分时,它不起作用。
如果有人可以写一个Wami Recorder for Dummies的答案,那就太棒了。
我在CakePHP 2.0中使用它,如果有人知道如何在该框架内使用它。
基本上我所要做的就是录制音频,将文件保存到目录,并拥有POST信息,以便能够将有关文件的某些细节保存到数据库。
答案 0 :(得分:14)
是的,文档不是很清楚。昨天我整个下午都在搞清楚。这是一个适用于我本地计算机的简单实现。以下文件存储在我的Apache文档根目录下的“/ temp / wami / test”中,因此URL为“http:// localhost / temp / wami / test /”:
的index.html
recorder.js
save_file.php
Wami.swf
的index.html
<!-- index.html -->
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script></script>
<script src="recorder.js"></script>
</head>
<body>
<div id="recorder">
<button id="record">Record</button>
<button id="play">Play</button>
</div>
<div id="flash"></div>
</body>
<script>
// initialize Wami
Wami.setup({
id: 'flash' // where to put the flash object
});
// initialize some global vars
var recording = '';
var recordingUrl = '';
var playBackUrl = '';
// get button elements
var record = $('#record');
var play = $('#play');
// define functions
function startRecording() {
recording = 'temp.wav';
recordingUrl = 'http://localhost/temp/wami/test/save_file.php?filename=' + recording;
Wami.startRecording(recordingUrl);
// update button attributes
record
.html('Stop')
.unbind()
.click(function() {
stopRecording();
});
}
function stopRecording() {
Wami.stopRecording();
// get the recording for playback
playBackUrl = 'http://localhost/temp/wami/test/' + recording;
// update button attributes
record
.html('Record')
.unbind()
.click(function() {
startRecording();
});
}
function startPlaying() {
Wami.startPlaying(playBackUrl);
// update button attributes
play
.html('Stop')
.unbind()
.click(function() {
stopPlaying();
});
}
function stopPlaying() {
Wami.stopPlaying();
// update button attributes
play
.html('Play')
.unbind()
.click(function() {
startPlaying();
});
}
// add initial click functions
record.click(function() {
startRecording();
});
play.click(function() {
startPlaying();
});
</script>
</html>
save_file.php
<?php
/* save_file.php */
// get the filename
parse_str($_SERVER['QUERY_STRING'], $params);
$file = isset($params['filename']) ? $params['filename'] : 'temp.wav';
// save the recorded audio to that file
$content = file_get_contents('php://input');
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
应该这样做。不幸的是,似乎没有办法暂停然后恢复录制。每次开始录制时都会覆盖以前的音频。似乎也没有办法检索有关音频文件的信息(例如长度,大小)。有关录像机功能的完整列表,请参阅Wami录像机文件(recorder.js)。