2016-04-30 10 views
0

私は、ユーザーがボタンを押すと、サウンド(サーバー側でmp3ファイル)を作成するシンプルなWebアプリケーションを構築しています。ノードjsでmp3ファイルをどのように配信できますか?

//html file 
<script> 
    function playSound() { 
    document.getElementById('play').play(); 
    } 
</script> 
<body> 
    <audio id='play', src='http://127.0.0.1:1337/', type='audio/mpeg' 
     <button onclick='playSound()' class='btn btn-danger btn-circle btn-lg'> 
      <i class='fa fa-5x fa-fire'> 
</body> 


//app.js 
app.get('/music.mp3', function(req, res){ 
    ms.pipe(req, res, "/music.mp3"); 
}); 

audio属性にオンラインソースを挿入しても動作しますが、ローカルサーバーファイルを提供しません。これをどうすれば解決できますか?

ありがとうございます!

答えて

1

画像、CSSファイル、JavaScriptファイルなどの静的ファイル、オーディオを提供するには、Expressでexpress.staticビルトインミドルウェア機能を使用します。

私はすでにこの種の質問に答えています。この回答を見る - res.sendFile(path.join(__dirname, '../public', 'mapv02.html'));

+0

ありがとう、私はすでに考え出しました。しかし、早くあなたの答えを得ることができたらいいなあ – jaykodeveloper

関連する問題