2

私は電子で音楽プレーヤーを構築しています。メイン プロセスでは、すべてのイベントをコンテンツ管理し、メインで作成した 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 個のフォームを試しても解決策はありません。

なぜそれが起こっているのですか?

4

1 に答える 1

0

UPDATE

I found something based off of your error:

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()

It's race condition between play() and pause()

Try:

var waitTime = 150;

setTimeout(function () {      
  if (el.paused) {
    el.play();
  }
}, waitTime);


OLD

When changing src of an audio or video tag, you have to invoke the .load() method before the .play() method. The change is applied and commented in the Snippet below. Not tested for your circumstances of course.

SNIPPET

ipc.on('toPlay', (event, data) => {
  console.log('http://localhost:9999/' + data[0].toString());

  audio_tag.src = 'http://localhost:9999/' + data[0].toString();
  play = true;

  //  .load() needs to be right before .play()
  /*~~~~~~~~~~~~~~~~~~~~~~~*/
  audio_tag.load();
  //~~~~~~~~~~~~~~~~~~~~~~~*/
  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]]);
  }
});

于 2016-11-28T19:38:17.103 に答える