私は電子で音楽プレーヤーを構築しています。メイン プロセスでは、すべてのイベントをコンテンツ管理し、メインで作成した http サーバーによってレンダラーに音楽をロードするので、audio
タグには のsrc
ような属性がありsrc = http://localhost:9999
ます。曲は、webtorrent を使用して torrent からダウンロードされます。私の問題は、最初のトレントには再生するコンテンツがこれ以上ないため、現在再生中のトレントを変更する場合です。オーディオは開始されませんが、メインプロセスにログオンすると、オーディオがhttpサーバーにロードされていると言えます。また、この 2 番目の torrent の他の曲を手動でクリックすると、音声は正常に機能しますが、コンソールに次のエラーが表示されます。
Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()
オーディオ タグ src を設定する関数は次のとおりです。
ipc.on('toPlay', (event, data) => {
console.log('http://localhost:9999/' + data[0].toString());
audio_tag.src = 'http://localhost:9999/' + data[0].toString();
play = true;
audio_tag.play();
audio_tag.onended = function(){
console.log('play end, to play ' + (data[0]+1).toString() + 'from torrent number: ' + data[1].toString());
ipc.send('getPlayData', [data[0]+1, data[1]]);
}
})
完全なdata[0]
URL はhttp://localhost:9999/<index of file>
メイン プロセス send は、次のような ipc メッセージを送信します。
ipc.on('getPlayData', function(event, data) {
var torrent = data[1];
var file = data[0];
if((file <= downloaderInstance.getTorrentFiles(torrent).length) && (downloaderInstance.getTorrentFiles(torrent)[file].name.indexOf('mp3') != -1)){
var i = file;
while(downloaderInstance.getTorrentFiles(torrent)[i].name.indexOf('mp3') == -1 &&
file <= downloaderInstance.getTorrentFiles(torrent).length){
file++;
}
} else {
torrent++;
}
if(torrent <= downloaderInstance.getNTorrents() && torrent != data[1]){
file = 0;
while(downloaderInstance.getTorrentFiles(torrent)[file].name.indexOf('mp3') == -1 &&
file <= downloaderInstance.getTorrentFiles(torrent).length){
file++;
}
} else if (torrent >= downloaderInstance.getNTorrents() && torrent != data[1]){
torrent = 0;
file = 0;
while(downloaderInstance.getTorrentFiles(torrent)[file].name.indexOf('mp3') == -1 &&
file <= downloaderInstance.getTorrentFiles(torrent).length){
file++;
}
}
if(torrent != currentPlayingTorrent){
currentPlayingTorrent = torrent;
if(currentPlayingTorrent != undefined)
downloaderInstance.closeTorrentServer();
downloaderInstance.initTorrentServer(currentPlayingTorrent);
downloaderInstance.listen();
}
console.log(file + ' ' + torrent);
console.log('toplay ' + file.toString() + '(' + downloaderInstance.getTorrentFiles(torrent)[file].name + ')' + ' from ' + torrent.toString());
event.sender.send('toPlay', [file, torrent]);
})
エラーは torrent の変更でのみ発生し、100 個のフォームを試しても解決策はありません。
なぜそれが起こっているのですか?