【问题标题】:How is the Wami Recorder actually implemented?Wami Recorder 是如何实际实现的?
【发布时间】:2012-02-20 05:50:45
【问题描述】:

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

基本上,如何实施 Wami Recorder?我在网站上看到过,它在那里工作得很好,但是当我下载它并尝试在 localhost 中使用它作为 Xampp 的一部分时,它不起作用。

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

如果有人特别知道如何在该框架中使用它,我将在 CakePHP 2.0 中使用它。

基本上我要做的就是录制音频,将文件保存到目录,并拥有 POST 信息以便能够将有关文件的某些详细信息保存到数据库。

【问题讨论】:

    标签: javascript flash cakephp-2.0


    【解决方案1】:

    是的,文档不是很清楚。我昨天花了整个下午才弄清楚。这是一个在我的本地机器上工作的简单实现。以下文件存放在我的Apache文档根目录下“/temp/wami/test”,所以URL是“http://localhost/temp/wami/test/”:

    index.html
    记录器.js
    保存文件.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>
    

    保存文件.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)。

    【讨论】:

    • 我正要回答,但我没有得到录音功能
    • 谢谢,工作就像一个魅力!确保将要保存文件的目录设为可写:-)
    猜你喜欢
    • 1970-01-01
    • 2012-08-18
    • 2013-07-16
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 2018-12-30
    相关资源
    最近更新 更多