2012-02-20 50 views
9

我對Wami Recorder很新,而且我從來沒有用過Flash,所以這實際上可能是一個愚蠢的問題。Wami記錄器是如何實際執行的?

基本上,人們如何去實施Wami Recorder?我在網站上看到了它,它在那裏效果很好,但是當我下載它並嘗試在本地主機中使用它作爲Xampp的一部分時,它不起作用。

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

我在CakePHP 2.0中使用這個,如果有人知道如何在該框架內使用它。

基本上我所要做的就是錄製音頻,將文件保存到一個目錄,並讓POST信息能夠將某些關於該文件的細節保存到數據庫中。

回答

15

是的,文件不是很清楚。我昨天整個下午都在搞清楚。這是一個適用於我的本地機器的簡單實現。下面的文件都存儲在我的Apache文檔根目錄中的「/溫度/瓦米/測試」,所以網址爲「http://本地主機/溫度/瓦米/測試/」:

的index.html
記錄。 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)以獲取錄音機功能的完整列表。

+0

非常感謝你! – 2012-03-17 02:31:57

+0

我正在拋出答案,但我沒有得到錄音功能 – ronan 2013-05-27 07:49:54

+0

謝謝,像一個魅力工作!確保你將目錄保存爲可寫的文件夾:-) – 2013-07-13 10:46:52