我是 Wami Recorder 的新手,而且我从来没有使用过 Flash,所以这实际上可能是一个愚蠢的问题。
基本上,如何实现 Wami Recorder?我在网站上看到它,它在那里运行得很好,但是当我下载它并尝试在本地主机中将它作为 Xampp 的一部分使用时,它不起作用。
如果有人能写出 Wami Recorder for Dummies 答案,那就太棒了。
如果有人特别知道如何在该框架内使用它,我将在 CakePHP 2.0 中使用它。
基本上我想做的就是录制音频,将文件保存到一个目录,并获得 POST 信息以便能够将文件的某些详细信息保存到数据库中。
最佳答案
是的,文档不是很清楚。我昨天整个下午都在想办法。这是一个在我的本地机器上运行的简单实现。以下文件存储在我的 Apache 文档根目录下的“/temp/wami/test”中,因此 URL 为“http://localhost/temp/wami/test/”:
index.html
录音机.js
保存文件.php
瓦米.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>
保存文件.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)。
关于javascript - Wami Recorder实际上是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9356739/