Skip to content

Commit

Permalink
More tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Oct 16, 2023
1 parent 7cbc2a7 commit e843097
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/video-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,6 @@ export class BabyVideoElement extends HTMLElement {
break;
}
}
if (direction === Direction.BACKWARD) {
frames.reverse();
}
this.#audioContext ??= this.#initializeAudio(firstFrame.sampleRate);
this.#renderAudioFrame(frames, currentTimeInMicros, direction);
// Decode more frames (if we now have more space in the queue)
Expand All @@ -1098,18 +1095,20 @@ export class BabyVideoElement extends HTMLElement {
) {
const firstFrame = frames[0];
const lastFrame = frames[frames.length - 1];
let firstTimestamp = firstFrame.timestamp;
let lastTimestamp = lastFrame.timestamp + lastFrame.duration;
if (direction === Direction.BACKWARD) {
[firstTimestamp, lastTimestamp] = [lastTimestamp, firstTimestamp];
}
const firstTimestamp = firstFrame.timestamp;
const lastTimestamp = lastFrame.timestamp + lastFrame.duration;
if (DEBUG) {
console.log(
`render audio frames start=${firstTimestamp} end=${lastTimestamp} duration=${
lastTimestamp - firstTimestamp
} count=${frames.length}`
);
}
// For reverse playback, first put the frames back in their original order,
// so we can reverse the individual samples later.
if (direction === Direction.BACKWARD) {
frames.reverse();
}
// Create an AudioBuffer containing all frame data
const { numberOfChannels, sampleRate } = frames[0];
const audioBuffer = new AudioBuffer({
Expand Down

0 comments on commit e843097

Please sign in to comment.