Wami记录器如何实际执行? [英] How is the Wami Recorder actually implemented?

查看:207
本文介绍了Wami记录器如何实际执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Wami Recorder很陌生,从来没有使用Flash,所以这可能是一个愚蠢的问题。



基本上,如何去实施Wami记录器?我已经在网站上看到了它,它在那里效果很好,但是当我下载它并尝试在本地主机中使用它作为Xampp的一部分时,它不起作用。



如果有人能写一个Wami Recorder for Dummies答案,那就太棒了。



我在CakePHP 2.0中使用了这个功能,如果有人知道如何在这个框架中使用它。



基本上我所要做的就是记录音频,将文件保存到一个目录,并让POST信息能够将关于该文件的某些细节保存到数据库。

是的,文档不是很清楚。我昨天整个下午都在想这个。这是一个在我的本地机器上运行的简单实现。以下文件存储在我的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.jstype =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>记录< / button>
< button id =play>播放< / button>
< / div>
< div id =flash>< / div>
< / body>

< script>
//初始化Wami
Wami.setup({
id:'flash'//在哪里放置flash对象
});

//初始化一些全局变量
var recording ='';
var recordingUrl ='';
var playBackUrl ='';

//获取按钮元素
var record = $('#record');
var play = $('#play');

//定义函数
函数startRecording(){
recording ='temp.wav';
recordingUrl ='http://localhost/temp/wami/test/save_file.php?filename ='+ recording;
Wami.startRecording(recordingUrl);
//更新按钮属性
记录
.html('Stop')
.unbind()
.click(function(){
stopRecording );
});


function stopRecording(){
Wami.stopRecording();
//获取播放的记录
playBackUrl ='http:// localhost / temp / wami / test /'+ recording;
//更新按钮属性
记录$ b $ .html('Record')
.unbind()
.click(function(){
startRecording( );
});


function startPlaying(){
Wami.startPlaying(playBackUrl);
//更新按钮属性
播放
.html('Stop')
.unbind()
.click(function(){
stopPlaying( );
});


function stopPlaying(){
Wami.stopPlaying();
//更新按钮属性
播放
.html('播放')
.unbind()
.click(function(){
startPlaying );
});


//添加初始点击函数
record.click(function(){
startRecording();
});

play.click(function(){
startPlaying();
});
< / script>

< / html>

save_file.php

 <?php 
/ * save_file.php * /

//获取文件名
parse_str($ _ SERVER ['QUERY_STRING'],$ params );
$ file = isset($ params ['filename'])? $ params ['filename']:'temp.wav';
//将录制的音频保存到该文件
$ content = file_get_contents('php:// input');
$ fh = fopen($ file,'w')或死(无法打开文件);
fwrite($ fh,$ content);
fclose($ fh);

应该这样做。不幸的是,似乎没有办法暂停然后恢复录制。每次开始录制时,都会覆盖以前的音频。还似乎没有检索关于音频文件的信息(例如长度,大小)的方式。请参阅Wami录像机文件(recorder.js)以获取录像机功能的完整列表。

I'm very new to the Wami Recorder, and I've never worked with Flash at all, so this may actually be a dumb question.

Basically, how does one go about implementing the Wami Recorder? I've seen it on the website, and it works great on there, but when I download it and try to use it within localhost as part of Xampp, it doesn't work.

If someone could kinda write up a Wami Recorder for Dummies answer, that'd be totally awesome.

I'm using this in CakePHP 2.0 if anyone knows especially how to use it within that framework.

Basically all I'm trying to do is record audio, save the file to a directory, and have POST information to be able to save certain details about the file to a database.

解决方案

Yeah, the documentation is not very clear. I spent all afternoon yesterday figuring it out. Here's a simple implementation that works on my local machine. The following files are stored under my Apache document root in "/temp/wami/test", so the URL is "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);

That should do it. Unfortunately, there doesn't appear to be a way to pause and then resume recording. Each time you start recording it overwrites the previous audio. There also doesn't appear to be a way to retrieve information about the audio file (e.g. length, size). See the Wami recorder file (recorder.js) for a full list of recorder functions.

这篇关于Wami记录器如何实际执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆