@axium/client 0.33.3 → 0.33.5

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.
@@ -10,27 +10,38 @@
10
10
  }
11
11
 
12
12
  const { media, children }: Props = $props();
13
+
14
+ const duration = $derived(media.knownDuration);
13
15
  </script>
14
16
 
15
17
  <div class="MediaControls">
16
18
  <button class="reset icon-text" onclick={media.click}>
17
19
  <Icon i={media.ended ? 'arrow-rotate-right' : media.paused ? 'play' : 'pause'} />
18
20
  </button>
19
- <div class="timeline">
21
+ <div class={['timeline', !duration && 'unknown-duration']}>
20
22
  <div class="timeline-track">
21
23
  {#each media.buffered || [] as { start, end }}
22
24
  <div
23
25
  class="buffered-range"
24
- style:left="{(start / (media.duration || 1)) * 100}%"
25
- style:width="{((end - start) / (media.duration || 1)) * 100}%"
26
+ style:left="{(start / duration) * 100}%"
27
+ style:width="{((end - start) / duration) * 100}%"
26
28
  ></div>
27
29
  {/each}
28
- <div class="played-range" style:width="{(media.currentTime / (media.duration || 1)) * 100}%"></div>
30
+ <div class="played-range" style:width="{(media.currentTime / duration) * 100}%"></div>
29
31
  </div>
30
- <div class="timeline-thumb" style:left="{(media.currentTime / (media.duration || 1)) * 100}%">
32
+ <div class="timeline-thumb" style:left="{(media.currentTime / duration) * 100}%">
31
33
  <Icon i="pipe" />
32
34
  </div>
33
- <input class="seek-input" type="range" min="0" max={media.duration || 1} step="0.01" bind:value={media.currentTime} />
35
+
36
+ <input
37
+ class="seek-input"
38
+ type="range"
39
+ min="0"
40
+ max={duration || 1}
41
+ step="0.01"
42
+ disabled={!duration}
43
+ bind:value={media.currentTime}
44
+ />
34
45
  </div>
35
46
  <div class="times">
36
47
  <span>{formatDuration(media.currentTime)}</span>
@@ -69,6 +80,14 @@
69
80
  height: 8px;
70
81
  display: flex;
71
82
  align-items: center;
83
+
84
+ &.unknown-duration {
85
+ opacity: 0.5;
86
+
87
+ .seek-input {
88
+ cursor: default;
89
+ }
90
+ }
72
91
  }
73
92
 
74
93
  .timeline-track {
package/lib/Video.svelte CHANGED
@@ -16,6 +16,7 @@
16
16
  <div class="Video" onkeydown={media.keydown}>
17
17
  <video
18
18
  src={rest.src}
19
+ preload="metadata"
19
20
  bind:this={media.element}
20
21
  bind:currentTime={media.currentTime}
21
22
  bind:duration={media.duration}
@@ -65,15 +65,22 @@ export class MediaState {
65
65
  }
66
66
  };
67
67
 
68
+ /** The duration, or 0 when it isn't known yet (NaN until metadata loads, Infinity for streams) */
69
+ get knownDuration(): number {
70
+ return Number.isFinite(this.duration) && this.duration > 0 ? this.duration : 0;
71
+ }
72
+
68
73
  keydown = (e: KeyboardEvent) => {
69
74
  switch (e.key) {
70
75
  case 'ArrowLeft':
71
76
  e.preventDefault();
77
+ if (!this.knownDuration) break;
72
78
  this.currentTime = Math.max(0, this.currentTime - 10);
73
79
  break;
74
80
  case 'ArrowRight':
75
81
  e.preventDefault();
76
- this.currentTime = Math.min(this.duration, this.currentTime + 10);
82
+ if (!this.knownDuration) break;
83
+ this.currentTime = Math.min(this.knownDuration, this.currentTime + 10);
77
84
  break;
78
85
  case 'ArrowUp':
79
86
  this.volume = Math.min(1, this.volume + 0.1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.33.3",
3
+ "version": "0.33.5",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",