@omnimedia/omnitool 1.1.0-34 → 1.1.0-36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnimedia/omnitool",
3
- "version": "1.1.0-34",
3
+ "version": "1.1.0-36",
4
4
  "description": "open source video processing tools",
5
5
  "license": "MIT",
6
6
  "author": "Przemysław Gałęzki",
@@ -42,9 +42,9 @@ export function makeWebCodecsSampler(
42
42
  audio: {
43
43
  getStream: async function*() {
44
44
  const source = resolveMedia(item.mediaHash)
45
- const startUs = item.start
46
- const endUs = (item.start + item.duration)
47
- const audio = driver.decodeAudio({source, start: startUs, end: endUs})
45
+ const start = item.start / 1000
46
+ const end = (item.start + item.duration) / 1000
47
+ const audio = driver.decodeAudio({source, start, end})
48
48
  const audioStream = new AudioStream(audio.getReader())
49
49
  yield* audioStream.stream()
50
50
  },
@@ -54,9 +54,9 @@ export class Filmstrip {
54
54
  return this.options.frequency
55
55
  }
56
56
 
57
- #computeActiveRange([start, end]: TimeRange): TimeRange {
57
+ #computeActiveRange([start, end]: TimeRange, margin = 1): TimeRange {
58
58
  const tileSize = end - start
59
- return [start - tileSize, end + tileSize]
59
+ return [start - tileSize * margin, end + tileSize * margin]
60
60
  }
61
61
 
62
62
  async #generateTiles() {
@@ -106,15 +106,20 @@ export class Filmstrip {
106
106
  * @param visibleRange - The current timeline viewport as a [start, end] tuple in seconds.
107
107
  */
108
108
  set range(visibleRange: TimeRange) {
109
- const newRange = this.#computeActiveRange(visibleRange)
110
- // Avoid redundant updates
111
- if (
112
- this.#activeRange[0] === newRange[0] &&
113
- this.#activeRange[1] === newRange[1]
114
- )
115
- return
109
+ const [visStart, visEnd] = visibleRange
110
+ const visibleSize = visEnd - visStart
111
+ const [actStart, actEnd] = this.#activeRange
112
+
113
+ // trigger when we're 1x visible width away from margin edges
114
+ const leftTrigger = actStart + visibleSize
115
+ const rightTrigger = actEnd - visibleSize
116
+
117
+ const nearLeftEdge = visStart < leftTrigger
118
+ const nearRightEdge = visEnd > rightTrigger
119
+
120
+ if (!nearLeftEdge && !nearRightEdge) return
116
121
 
117
- this.#activeRange = newRange
122
+ this.#activeRange = this.#computeActiveRange(visibleRange, 2)
118
123
  this.#update()
119
124
  }
120
125