@axium/client 0.36.2 → 0.36.4
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/lib/reactive/media.svelte.ts +20 -0
- package/package.json +1 -1
|
@@ -76,11 +76,13 @@ export class MediaState {
|
|
|
76
76
|
e.preventDefault();
|
|
77
77
|
if (!this.knownDuration) break;
|
|
78
78
|
this.currentTime = Math.max(0, this.currentTime - 10);
|
|
79
|
+
this.updateAttached();
|
|
79
80
|
break;
|
|
80
81
|
case 'ArrowRight':
|
|
81
82
|
e.preventDefault();
|
|
82
83
|
if (!this.knownDuration) break;
|
|
83
84
|
this.currentTime = Math.min(this.knownDuration, this.currentTime + 10);
|
|
85
|
+
this.updateAttached();
|
|
84
86
|
break;
|
|
85
87
|
case 'ArrowUp':
|
|
86
88
|
this.volume = Math.min(1, this.volume + 0.1);
|
|
@@ -111,6 +113,18 @@ export class MediaState {
|
|
|
111
113
|
/** Seek to a time, clamped to the media's duration when known */
|
|
112
114
|
seek(time: number) {
|
|
113
115
|
this.currentTime = this.knownDuration ? Math.min(this.knownDuration, Math.max(0, time)) : Math.max(0, time);
|
|
116
|
+
this.updateAttached();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected isAttached: boolean = false;
|
|
120
|
+
|
|
121
|
+
protected updateAttached() {
|
|
122
|
+
if (!this.isAttached) return;
|
|
123
|
+
|
|
124
|
+
globalThis.navigator?.mediaSession?.setPositionState({
|
|
125
|
+
duration: this.knownDuration,
|
|
126
|
+
position: this.currentTime,
|
|
127
|
+
});
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
attachToSession(next?: (backward: boolean) => void) {
|
|
@@ -118,9 +132,14 @@ export class MediaState {
|
|
|
118
132
|
|
|
119
133
|
if (!session) return;
|
|
120
134
|
|
|
135
|
+
this.isAttached = true;
|
|
136
|
+
|
|
137
|
+
this.updateAttached();
|
|
138
|
+
|
|
121
139
|
session.setActionHandler('play', () => {
|
|
122
140
|
if (this.ended) this.currentTime = 0;
|
|
123
141
|
this.paused = false;
|
|
142
|
+
this.updateAttached();
|
|
124
143
|
});
|
|
125
144
|
session.setActionHandler('pause', () => {
|
|
126
145
|
this.paused = true;
|
|
@@ -128,6 +147,7 @@ export class MediaState {
|
|
|
128
147
|
session.setActionHandler('stop', () => {
|
|
129
148
|
this.paused = true;
|
|
130
149
|
this.currentTime = 0;
|
|
150
|
+
this.updateAttached();
|
|
131
151
|
});
|
|
132
152
|
session.setActionHandler('seekbackward', details => {
|
|
133
153
|
if (!this.knownDuration) return;
|