私のオブジェクトでは、既にオブジェクト ( ) に格納されている (有効な) を再生するゲイン ノード ( ) に接続されたAudioBufferSourceNode
オブジェクト ( ) を取得しました。this.bSrc
this.audioDestination
AudioBuffer
this.audioBuffer
this.audioDestination
がオーディオ コンテキストの最終宛先に接続されていて、オブジェクト ( ) でメソッドthis.mainContext.destination
を呼び出すと、正常に再生されます。start(0)
AudioBufferSourceNode
this.bSrc
がオーディオ コンテキストの最終目的地にまだ接続されていない場合、バッファは再生されませんthis.audioDestination
が(問題ありません)、接続が確立されるまで再生が遅延されます (したがって、AudioBufferSourceNode の再生がいつ終了するかについての仮定は無効になります)。 .
私は現在、プラグイン アーキテクチャを実装しています。このアーキテクチャでは、すべてのプラグインに audioDestination ゲイン ノードがあり、最終的なオーディオ コンテキストの宛先に間接的に接続されているかどうかを認識していません (認識してはなりません)。私にとって論理的に思えるのは、AudioBufferSourceNode が最終的なオーディオ コンテキストの宛先に接続されていなくても、すぐに「再生」して終了する必要があるということです。しかし、このようにはうまくいかないようです。私は正しいですか、それとも間違っていますか?この動作を変更する方法はありますか?
コード:
/* Create the audio Context. */
this.mainContext = new webkitAudioContext;
/* Create an audio gain node */
this.audioDestination = this.mainContext.createGainNode();
/* [...] An AudioBuffer gets decoded and stored into this.audioBuffer*/
/* Create an AudioBufferSourceNode and try to play it immediately */
this.bSrc = this.audioContext.createBufferSource();
this.bSrc.connect (this.audioDestination);
this.bSrc.buffer = this.audioBuffer;
this.bSrc.start(0);
/* Create a callback for when the AudioBufferSourceNode finishes playing */
if (!this.bSrc.loop) {
var pbTimer = setTimeout(function() {
this.playFinishedCallback();
}.bind(this), this.audioBuffer.duration * 1000 / this.bSrc.playbackRate.value);
}
/* Connect this.audioDestination to the final AudioContext destination */
/* If this statement is executed after the previous ones, playback will start NOW */
this.audioDestination.connect(this.mainContext.destination);