Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function PushBuffer (AudioBuffer)
- {
- // Create new audio source for the buffer
- var SourceNode = Self.SoundContext.createBufferSource();
- // Make sure the node deletes itself after playback
- SourceNode.onended = function () {
- var ThisNode = SourceNode;
- ThisNode.disconnect();
- ThisNode = null;
- }
- // Prevent looping (the standard says that it should be off by default)
- SourceNode.loop = false;
- // Pass audio data to source
- SourceNode.buffer = AudioBuffer;
- //Connect the source to the gain node
- SourceNode.connect(Self.GainNode);
- // Check if this is the first buffer we received
- if (Self.NextTime == 0.0)
- {
- // Start playing now
- Self.NextTime = Self.SoundContext.currentTime;
- }
- // Schedule playback
- console.log("Current time: "+Self.SoundContext.currentTime);
- console.log("Duration: "+AudioBuffer.duration);
- end = Self.NextTime+AudioBuffer.duration
- console.log("Play at: "+Self.NextTime+" End at: "+end);
- SourceNode.start(Self.NextTime);
- //SourceNode.start(Self.SoundContext.currentTime);
- //SourceNode.start(0);
- // Move time forward
- Self.NextTime += AudioBuffer.duration;
- return;
- } // end push buffer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement