電子を使ってトレントからストリーミングサウンドを再生しようとしています。これを行うには、https://github.com/feross/webtorrentを使用して、電子の主要な処理のすべてのデータをダウンロードします。私は音を選択すると、その後、私はプレーして、フォロー機能にレンダラーproccessをHTMLに送信するファイルのストリームを取得するダウンロードする「toPlay」というメッセージを配置する必要があり、ファイルのレンダリングパラメータを伝えるバッファとパイプデータを作成してそれを再生するjavascript
ipc.on('getPlayData', function(event, data){
console.log('get file data stream');
in_play = data[1];
//Crea el stream del archivo que se va a reproducir
var streamfile = downloaderInstance.getFileToPlay(data[0], data[1]).createReadStream();
//se envia la longiud del archivo en bytes para el buffer.
event.sender.send('toPlay', [downloaderInstance.getFileToPlay(data[0], data[1]).name,
downloaderInstance.getFileToPlay(data[0], data[1]).length]);
streamfile.on('data', function(chunk){
event.sender.send('addData', chunk);
});
htmlとデータでは、私がトレントのシーダーから得たすべてのデータを送信します。
レンダラーproccesで私はhttps://github.com/feross/render-mediaでそれを使用するためにバッファにデータを取得しますが、私はまたjavascriptのWebAudioApiで動作しようとします。私は以下の関数でデータを管理します:
ipc.on('toPlay', (event, data) => {
console.log("to play: " + data[0]);
var buf = [];
var stream_length = parseInt(data[1]);
var stream_data = Buffer.alloc(stream_length);
ipc.on('addData', (event, data) => {
buf.push(data);
stream_data = Buffer.concat(buf);
})
var file = {
name: data[0],
createReadStream: function(opts){
//console.log(stream_data.length);
return from([stream_data.slice(0, stream_length) ]);
}
}
//console.log(file.createReadStream);
render.render(file, 'audio', [true, true, stream_length], function(err, elem){
if(err){ return console.log('error appending') }
})
})
ここで、それはオーディオDOMノードでメディアソースを再生する関数です。私の問題は、バッファ内のファイルの完全なメモリを予約し、レンダリング機能をファイルの完全な持続時間に設定していますが、ipcでニュースが受信されたときに既にダウンロードしたデータを再生し、これを行う方法を見つけることはありません。
オーディオオブジェクトの '
あなたに私にいくつかのリンクや例を教えてもらえますか? @JuanjoSalvador – rafaelleru
これはあなたを助けるかもしれないhttp://www.inserthtml.com/2013/03/custom-html5-video-player/ –