@maas/vue-equipment 1.0.0-beta.11 → 1.0.0-beta.13
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/dist/nuxt/module.json +1 -1
- package/dist/plugins/.turbo/turbo-lint.log +2 -2
- package/dist/plugins/MagicDraggable/src/components/MagicDraggable.vue +2 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudio.vue +11 -6
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudioControls.vue +31 -10
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerAudioControls.vue.d.ts +8 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerDisplayTime.vue +6 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerMuxPopover.vue +5 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerOverlay.vue +6 -6
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerOverlay.vue.d.ts +3 -3
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerPoster.vue +5 -9
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerPoster.vue.d.ts +1 -2
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerProvider.vue +17 -23
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerProvider.vue.d.ts +5 -5
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerTimeline.vue +91 -83
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideo.vue +18 -7
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideoControls.vue +53 -24
- package/dist/plugins/MagicPlayer/src/components/MagicPlayerVideoControls.vue.d.ts +8 -6
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerAudioApi.d.ts +0 -4
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerAudioApi.mjs +6 -47
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerControlsApi.d.ts +4 -31
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerControlsApi.mjs +147 -234
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerMediaApi.d.ts +1 -15
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerMediaApi.mjs +17 -164
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.d.ts +0 -1
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerRuntime.mjs +6 -24
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerState.d.ts +7 -0
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerState.mjs +56 -0
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerVideoApi.d.ts +0 -5
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerVideoApi.mjs +7 -62
- package/dist/plugins/MagicPlayer/src/composables/useMagicPlayer.d.ts +32 -51
- package/dist/plugins/MagicPlayer/src/composables/useMagicPlayer.mjs +47 -0
- package/dist/plugins/MagicPlayer/src/symbols/index.d.ts +5 -2
- package/dist/plugins/MagicPlayer/src/symbols/index.mjs +10 -1
- package/dist/plugins/MagicPlayer/src/types/index.d.ts +29 -0
- package/package.json +4 -4
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerStateEmitter.d.ts +0 -15
- package/dist/plugins/MagicPlayer/src/composables/private/usePlayerStateEmitter.mjs +0 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
toRefs,
|
|
3
3
|
shallowRef,
|
|
4
4
|
computed,
|
|
5
5
|
watch,
|
|
@@ -8,65 +8,87 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
useResizeObserver,
|
|
10
10
|
useEventListener,
|
|
11
|
-
defaultWindow
|
|
11
|
+
defaultWindow,
|
|
12
|
+
useThrottleFn
|
|
12
13
|
} from "@vueuse/core";
|
|
14
|
+
import {
|
|
15
|
+
isIOS,
|
|
16
|
+
guardedReleasePointerCapture,
|
|
17
|
+
guardedSetPointerCapture
|
|
18
|
+
} from "@maas/vue-equipment/utils";
|
|
13
19
|
import { clampValue, mapValue } from "@maas/vue-equipment/utils";
|
|
14
|
-
import { usePlayerMediaApi } from "./usePlayerMediaApi.mjs";
|
|
15
20
|
import { usePlayerVideoApi } from "./usePlayerVideoApi.mjs";
|
|
16
|
-
import {
|
|
21
|
+
import { usePlayerState } from "./usePlayerState.mjs";
|
|
17
22
|
export function usePlayerControlsApi(args) {
|
|
23
|
+
const { id, barRef, trackRef, popoverRef } = args;
|
|
24
|
+
const { initializeState } = usePlayerState(toValue(id));
|
|
25
|
+
const state = initializeState();
|
|
26
|
+
const {
|
|
27
|
+
currentTime,
|
|
28
|
+
duration,
|
|
29
|
+
dragging,
|
|
30
|
+
controlsMouseEntered,
|
|
31
|
+
seekedTime,
|
|
32
|
+
seekedPercentage,
|
|
33
|
+
scrubbedPercentage,
|
|
34
|
+
thumbPercentage,
|
|
35
|
+
popoverOffsetX,
|
|
36
|
+
playing,
|
|
37
|
+
buffered,
|
|
38
|
+
controlsBarRect,
|
|
39
|
+
controlsTrackRect,
|
|
40
|
+
controlsPopoverRect
|
|
41
|
+
} = toRefs(state);
|
|
18
42
|
const resumePlay = shallowRef(false);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const { id, trackRef, barRef, popoverRef } = args;
|
|
23
|
-
const { buffered, duration, playing, currentTime } = usePlayerMediaApi({ id });
|
|
24
|
-
const { play, pause, seek } = usePlayerVideoApi({ id });
|
|
25
|
-
const dragging = shallowRef(false);
|
|
26
|
-
const mouseEntered = shallowRef(false);
|
|
27
|
-
const seekedTime = shallowRef(0);
|
|
28
|
-
const seekedPercentage = shallowRef(0);
|
|
29
|
-
const scrubbedPercentage = shallowRef(0);
|
|
30
|
-
const thumbPercentage = shallowRef(0);
|
|
31
|
-
const popoverOffsetX = shallowRef(0);
|
|
43
|
+
let cancelPointerup = void 0;
|
|
44
|
+
let cancelPointermove = void 0;
|
|
45
|
+
let cancelTouchend = void 0;
|
|
32
46
|
const bufferedPercentage = computed(() => {
|
|
33
|
-
if (!buffered)
|
|
47
|
+
if (!buffered.value) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
34
50
|
const endBuffer = buffered.value?.length > 0 ? buffered.value[0][1] : 0;
|
|
35
51
|
const percentage = endBuffer / duration.value * 100;
|
|
36
52
|
return clampValue(percentage, 0, thumbPercentage.value);
|
|
37
53
|
});
|
|
54
|
+
const { play, pause, seek } = usePlayerVideoApi({ id });
|
|
38
55
|
function getPopoverOffsetX() {
|
|
39
|
-
if (!
|
|
40
|
-
return
|
|
41
|
-
} else {
|
|
42
|
-
const trackFactor = barRect.value.width / trackRect.value.width;
|
|
43
|
-
const offsetXPercentage = Math.abs(trackRect.value.x - barRect.value.x) / barRect.value.width * 100;
|
|
44
|
-
const popoverWidthPercentage = popoverRect.value.width / barRect.value.width * 100;
|
|
45
|
-
const maxPercentage = 100 - popoverWidthPercentage;
|
|
46
|
-
const percentage = seekedPercentage.value / trackFactor + offsetXPercentage - popoverWidthPercentage / 2;
|
|
47
|
-
popoverOffsetX.value = clampValue(percentage, 0, maxPercentage);
|
|
56
|
+
if (!controlsTrackRect.value || !controlsPopoverRect.value || !controlsBarRect.value) {
|
|
57
|
+
return;
|
|
48
58
|
}
|
|
59
|
+
const trackFactor = controlsBarRect.value.width / controlsTrackRect.value.width;
|
|
60
|
+
const offsetXPercentage = Math.abs(controlsTrackRect.value.x - controlsBarRect.value.x) / controlsBarRect.value.width * 100;
|
|
61
|
+
const popoverWidthPercentage = controlsPopoverRect.value.width / controlsBarRect.value.width * 100;
|
|
62
|
+
const maxPercentage = 100 - popoverWidthPercentage;
|
|
63
|
+
const percentage = seekedPercentage.value / trackFactor + offsetXPercentage - popoverWidthPercentage / 2;
|
|
64
|
+
popoverOffsetX.value = clampValue(percentage, 0, maxPercentage);
|
|
49
65
|
}
|
|
50
66
|
function getTimelineTrackSize() {
|
|
51
67
|
if (!toValue(trackRef)) {
|
|
52
68
|
return;
|
|
53
69
|
}
|
|
54
|
-
|
|
55
|
-
thumbPercentage.value = 100 -
|
|
70
|
+
controlsTrackRect.value = toValue(trackRef).getBoundingClientRect();
|
|
71
|
+
thumbPercentage.value = 100 - controlsTrackRect.value.height / controlsTrackRect.value.width * 100;
|
|
56
72
|
}
|
|
57
73
|
function getPopoverSizes() {
|
|
58
74
|
if (!toValue(barRef) || !toValue(popoverRef)) {
|
|
59
75
|
return;
|
|
60
76
|
}
|
|
61
|
-
|
|
62
|
-
|
|
77
|
+
controlsBarRect.value = toValue(barRef).getBoundingClientRect();
|
|
78
|
+
controlsPopoverRect.value = toValue(popoverRef).getBoundingClientRect();
|
|
63
79
|
}
|
|
80
|
+
function getSizes() {
|
|
81
|
+
getTimelineTrackSize();
|
|
82
|
+
getPopoverSizes();
|
|
83
|
+
getPopoverOffsetX();
|
|
84
|
+
}
|
|
85
|
+
const getSizesThrottled = useThrottleFn(getSizes, 100);
|
|
64
86
|
function seekToTrackPosition(absX) {
|
|
65
|
-
if (!
|
|
66
|
-
|
|
87
|
+
if (!controlsTrackRect.value) {
|
|
88
|
+
return;
|
|
67
89
|
}
|
|
68
|
-
const relX = absX -
|
|
69
|
-
const percentage = Math.round(relX /
|
|
90
|
+
const relX = absX - controlsTrackRect.value.x - controlsTrackRect.value.height / 2;
|
|
91
|
+
const percentage = Math.round(relX / controlsTrackRect.value.width * 100);
|
|
70
92
|
seekedPercentage.value = clampValue(percentage, 0, thumbPercentage.value);
|
|
71
93
|
seekedTime.value = duration.value * mapValue(seekedPercentage.value, 0, thumbPercentage.value, 0, 100) / 100;
|
|
72
94
|
if (dragging.value) {
|
|
@@ -75,220 +97,111 @@ export function usePlayerControlsApi(args) {
|
|
|
75
97
|
}
|
|
76
98
|
getPopoverOffsetX();
|
|
77
99
|
}
|
|
78
|
-
function
|
|
79
|
-
getTimelineTrackSize();
|
|
80
|
-
getPopoverSizes();
|
|
81
|
-
mouseEntered.value = true;
|
|
82
|
-
}
|
|
83
|
-
function onMouseleave() {
|
|
84
|
-
mouseEntered.value = false;
|
|
100
|
+
function resetStateAndListeners() {
|
|
85
101
|
dragging.value = false;
|
|
86
|
-
|
|
102
|
+
cancelTouchend?.();
|
|
103
|
+
cancelPointerup?.();
|
|
104
|
+
cancelPointermove?.();
|
|
87
105
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
pause();
|
|
92
|
-
const x = e instanceof MouseEvent ? e.pageX : e.touches[0].pageX;
|
|
93
|
-
seekToTrackPosition(x);
|
|
94
|
-
}
|
|
95
|
-
function onPointerup() {
|
|
96
|
-
dragging.value = false;
|
|
106
|
+
function onPointerup(e) {
|
|
107
|
+
resetStateAndListeners();
|
|
108
|
+
guardedReleasePointerCapture({ event: e, element: barRef?.value });
|
|
97
109
|
if (resumePlay.value) {
|
|
98
110
|
play();
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
113
|
function onPointermove(e) {
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
if (!e.isPrimary) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
getSizesThrottled();
|
|
118
|
+
e.stopImmediatePropagation();
|
|
119
|
+
e.stopPropagation();
|
|
120
|
+
seekToTrackPosition(e.clientX);
|
|
104
121
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
() => {
|
|
124
|
-
getTimelineTrackSize();
|
|
125
|
-
getPopoverSizes();
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
passive: true
|
|
122
|
+
function onPointerdown(e) {
|
|
123
|
+
if (dragging.value) {
|
|
124
|
+
return;
|
|
125
|
+
} else {
|
|
126
|
+
guardedSetPointerCapture({ event: e, element: barRef?.value });
|
|
127
|
+
resumePlay.value = playing.value;
|
|
128
|
+
dragging.value = true;
|
|
129
|
+
pause();
|
|
130
|
+
getSizes();
|
|
131
|
+
cancelPointerup = useEventListener(document, "pointerup", onPointerup);
|
|
132
|
+
cancelPointermove = useEventListener(
|
|
133
|
+
document,
|
|
134
|
+
"pointermove",
|
|
135
|
+
onPointermove,
|
|
136
|
+
{ passive: false }
|
|
137
|
+
);
|
|
138
|
+
cancelTouchend = isIOS() ? useEventListener(document, "touchend", onPointerup) : void 0;
|
|
139
|
+
onPointermove(e);
|
|
129
140
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
case "mouseEntered": {
|
|
141
|
-
mouseEntered.value = payload.value;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case "seekedTime": {
|
|
145
|
-
seekedTime.value = payload.value;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
case "seekedPercentage": {
|
|
149
|
-
seekedPercentage.value = payload.value;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
case "scrubbedPercentage": {
|
|
153
|
-
scrubbedPercentage.value = payload.value;
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
case "thumbPercentage": {
|
|
157
|
-
thumbPercentage.value = payload.value;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
case "popoverOffsetX": {
|
|
161
|
-
popoverOffsetX.value = payload.value;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "barRect": {
|
|
165
|
-
barRect.value = payload.value;
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case "trackRect": {
|
|
169
|
-
trackRect.value = payload.value;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case "popoverRect": {
|
|
173
|
-
popoverRect.value = payload.value;
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
141
|
+
}
|
|
142
|
+
function onMouseenter() {
|
|
143
|
+
getSizes();
|
|
144
|
+
controlsMouseEntered.value = true;
|
|
145
|
+
}
|
|
146
|
+
function onMouseleave() {
|
|
147
|
+
controlsMouseEntered.value = false;
|
|
148
|
+
if (!dragging.value) {
|
|
149
|
+
seekedTime.value = 0;
|
|
177
150
|
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
value
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
value
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
watch(seekedPercentage, (value) => {
|
|
204
|
-
emitter.emit("update", {
|
|
205
|
-
id: toValue(id),
|
|
206
|
-
api: "controls",
|
|
207
|
-
key: "seekedPercentage",
|
|
208
|
-
value
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
watch(scrubbedPercentage, (value) => {
|
|
212
|
-
emitter.emit("update", {
|
|
213
|
-
id: toValue(id),
|
|
214
|
-
api: "controls",
|
|
215
|
-
key: "scrubbedPercentage",
|
|
216
|
-
value
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
watch(bufferedPercentage, (value) => {
|
|
220
|
-
emitter.emit("update", {
|
|
221
|
-
id: toValue(id),
|
|
222
|
-
api: "controls",
|
|
223
|
-
key: "bufferedPercentage",
|
|
224
|
-
value
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
watch(thumbPercentage, (value) => {
|
|
228
|
-
emitter.emit("update", {
|
|
229
|
-
id: toValue(id),
|
|
230
|
-
api: "controls",
|
|
231
|
-
key: "thumbPercentage",
|
|
232
|
-
value
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
watch(popoverOffsetX, (value) => {
|
|
236
|
-
emitter.emit("update", {
|
|
237
|
-
id: toValue(id),
|
|
238
|
-
api: "controls",
|
|
239
|
-
key: "popoverOffsetX",
|
|
240
|
-
value
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
watch(resumePlay, (value) => {
|
|
244
|
-
emitter.emit("update", {
|
|
245
|
-
id: toValue(id),
|
|
246
|
-
api: "controls",
|
|
247
|
-
key: "resumePlay",
|
|
248
|
-
value
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
watch(barRect, (value) => {
|
|
252
|
-
if (!value) return;
|
|
253
|
-
emitter.emit("update", {
|
|
254
|
-
id: toValue(id),
|
|
255
|
-
api: "controls",
|
|
256
|
-
key: "barRect",
|
|
257
|
-
value
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
watch(trackRect, (value) => {
|
|
261
|
-
if (!value) return;
|
|
262
|
-
emitter.emit("update", {
|
|
263
|
-
id: toValue(id),
|
|
264
|
-
api: "controls",
|
|
265
|
-
key: "trackRect",
|
|
266
|
-
value
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
watch(popoverRect, (value) => {
|
|
270
|
-
if (!value) return;
|
|
271
|
-
emitter.emit("update", {
|
|
272
|
-
id: toValue(id),
|
|
273
|
-
api: "controls",
|
|
274
|
-
key: "popoverRect",
|
|
275
|
-
value
|
|
151
|
+
}
|
|
152
|
+
let watchTrack = null;
|
|
153
|
+
let watchPopover = null;
|
|
154
|
+
let watchBar = null;
|
|
155
|
+
let watchCurrentTime = null;
|
|
156
|
+
let resizeObserverTrack = null;
|
|
157
|
+
let resizeObserverPopover = null;
|
|
158
|
+
let resizeObserverBar = null;
|
|
159
|
+
let windowResizeCleanup = null;
|
|
160
|
+
function initialize() {
|
|
161
|
+
watchTrack = watch(() => trackRef, getTimelineTrackSize);
|
|
162
|
+
watchPopover = watch(() => popoverRef, getPopoverSizes);
|
|
163
|
+
watchBar = watch(() => barRef, getPopoverSizes);
|
|
164
|
+
watchCurrentTime = watch(currentTime, (value) => {
|
|
165
|
+
const percentage = value / duration?.value * 100;
|
|
166
|
+
scrubbedPercentage.value = mapValue(
|
|
167
|
+
percentage,
|
|
168
|
+
0,
|
|
169
|
+
100,
|
|
170
|
+
0,
|
|
171
|
+
thumbPercentage.value
|
|
172
|
+
);
|
|
276
173
|
});
|
|
277
|
-
|
|
174
|
+
resizeObserverTrack = useResizeObserver(trackRef, getTimelineTrackSize);
|
|
175
|
+
resizeObserverPopover = useResizeObserver(popoverRef, getPopoverSizes);
|
|
176
|
+
resizeObserverBar = useResizeObserver(barRef, getPopoverSizes);
|
|
177
|
+
windowResizeCleanup = useEventListener(
|
|
178
|
+
defaultWindow,
|
|
179
|
+
"resize",
|
|
180
|
+
() => {
|
|
181
|
+
getSizes();
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
passive: true
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function destroy() {
|
|
189
|
+
watchTrack?.();
|
|
190
|
+
watchPopover?.();
|
|
191
|
+
watchBar?.();
|
|
192
|
+
watchCurrentTime?.();
|
|
193
|
+
resizeObserverTrack?.stop();
|
|
194
|
+
resizeObserverPopover?.stop();
|
|
195
|
+
resizeObserverBar?.stop();
|
|
196
|
+
windowResizeCleanup?.();
|
|
197
|
+
}
|
|
278
198
|
return {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
seekedTime,
|
|
282
|
-
seekedPercentage,
|
|
283
|
-
scrubbedPercentage,
|
|
199
|
+
initialize,
|
|
200
|
+
destroy,
|
|
284
201
|
bufferedPercentage,
|
|
285
|
-
thumbPercentage,
|
|
286
|
-
popoverOffsetX,
|
|
287
202
|
onMouseenter,
|
|
288
203
|
onMouseleave,
|
|
289
204
|
onPointerdown,
|
|
290
|
-
|
|
291
|
-
onPointermove,
|
|
292
|
-
trackRect
|
|
205
|
+
onPointermove
|
|
293
206
|
};
|
|
294
207
|
}
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import { type Ref, type MaybeRef } from 'vue';
|
|
2
|
-
import type { Buffered } from '../../types/index.js';
|
|
3
2
|
export type UsePlayerMediaApiArgs = {
|
|
4
3
|
id: MaybeRef<string>;
|
|
5
4
|
mediaRef?: Ref<HTMLMediaElement | null>;
|
|
6
5
|
};
|
|
7
|
-
export declare function usePlayerMediaApi(args: UsePlayerMediaApiArgs):
|
|
8
|
-
currentTime: import("vue").ShallowRef<number, number>;
|
|
9
|
-
remainingTime: import("vue").ComputedRef<number>;
|
|
10
|
-
duration: import("vue").ShallowRef<number, number>;
|
|
11
|
-
seeking: import("vue").ShallowRef<boolean, boolean>;
|
|
12
|
-
volume: import("vue").ShallowRef<number, number>;
|
|
13
|
-
rate: import("vue").ShallowRef<number, number>;
|
|
14
|
-
waiting: import("vue").ShallowRef<boolean, boolean>;
|
|
15
|
-
ended: import("vue").ShallowRef<boolean, boolean>;
|
|
16
|
-
playing: import("vue").ShallowRef<boolean, boolean>;
|
|
17
|
-
stalled: import("vue").ShallowRef<boolean, boolean>;
|
|
18
|
-
buffered: Ref<[number, number][], Buffered | [number, number][]>;
|
|
19
|
-
muted: import("vue").ShallowRef<boolean, boolean>;
|
|
20
|
-
};
|
|
6
|
+
export declare function usePlayerMediaApi(args: UsePlayerMediaApiArgs): void;
|
|
21
7
|
export type UsePlayerMediaApiReturn = ReturnType<typeof usePlayerMediaApi>;
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ref,
|
|
3
|
-
shallowRef,
|
|
4
|
-
computed,
|
|
5
|
-
watch,
|
|
6
|
-
unref,
|
|
7
|
-
toValue
|
|
8
|
-
} from "vue";
|
|
1
|
+
import { toRefs, watch, unref, toValue } from "vue";
|
|
9
2
|
import { useEventListener, watchIgnorable } from "@vueuse/core";
|
|
10
|
-
import {
|
|
3
|
+
import { usePlayerState } from "./usePlayerState.mjs";
|
|
11
4
|
export function usePlayerMediaApi(args) {
|
|
12
|
-
const currentTime = shallowRef(0);
|
|
13
|
-
const duration = shallowRef(0);
|
|
14
|
-
const seeking = shallowRef(false);
|
|
15
|
-
const volume = shallowRef(1);
|
|
16
|
-
const rate = shallowRef(1);
|
|
17
|
-
const waiting = shallowRef(false);
|
|
18
|
-
const ended = shallowRef(false);
|
|
19
|
-
const playing = shallowRef(false);
|
|
20
|
-
const stalled = shallowRef(false);
|
|
21
|
-
const buffered = ref([]);
|
|
22
|
-
const muted = shallowRef(false);
|
|
23
5
|
const { mediaRef, id } = args;
|
|
24
|
-
const
|
|
6
|
+
const { initializeState } = usePlayerState(toValue(id));
|
|
7
|
+
const state = initializeState();
|
|
8
|
+
const {
|
|
9
|
+
currentTime,
|
|
10
|
+
duration,
|
|
11
|
+
seeking,
|
|
12
|
+
volume,
|
|
13
|
+
rate,
|
|
14
|
+
waiting,
|
|
15
|
+
ended,
|
|
16
|
+
playing,
|
|
17
|
+
stalled,
|
|
18
|
+
buffered,
|
|
19
|
+
muted
|
|
20
|
+
} = toRefs(state);
|
|
25
21
|
function timeRangeToArray(timeRanges) {
|
|
26
22
|
let ranges = [];
|
|
27
23
|
for (let i = 0; i < timeRanges.length; ++i)
|
|
@@ -127,147 +123,4 @@ export function usePlayerMediaApi(args) {
|
|
|
127
123
|
volume.value = el.volume;
|
|
128
124
|
muted.value = el.muted;
|
|
129
125
|
});
|
|
130
|
-
const emitter = usePlayerStateEmitter();
|
|
131
|
-
emitter.on("update", (payload) => {
|
|
132
|
-
if (payload.id !== toValue(id)) return;
|
|
133
|
-
if (payload.api === "media") {
|
|
134
|
-
switch (payload.key) {
|
|
135
|
-
case "currentTime":
|
|
136
|
-
currentTime.value = payload.value;
|
|
137
|
-
break;
|
|
138
|
-
case "duration":
|
|
139
|
-
duration.value = payload.value;
|
|
140
|
-
break;
|
|
141
|
-
case "seeking":
|
|
142
|
-
seeking.value = payload.value;
|
|
143
|
-
break;
|
|
144
|
-
case "volume":
|
|
145
|
-
volume.value = payload.value;
|
|
146
|
-
break;
|
|
147
|
-
case "rate":
|
|
148
|
-
rate.value = payload.value;
|
|
149
|
-
break;
|
|
150
|
-
case "waiting":
|
|
151
|
-
waiting.value = payload.value;
|
|
152
|
-
break;
|
|
153
|
-
case "ended":
|
|
154
|
-
ended.value = payload.value;
|
|
155
|
-
break;
|
|
156
|
-
case "playing":
|
|
157
|
-
playing.value = payload.value;
|
|
158
|
-
break;
|
|
159
|
-
case "stalled":
|
|
160
|
-
stalled.value = payload.value;
|
|
161
|
-
break;
|
|
162
|
-
case "buffered":
|
|
163
|
-
buffered.value = payload.value;
|
|
164
|
-
break;
|
|
165
|
-
case "muted":
|
|
166
|
-
muted.value = payload.value;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
watch(currentTime, (value) => {
|
|
172
|
-
emitter.emit("update", {
|
|
173
|
-
id: toValue(id),
|
|
174
|
-
api: "media",
|
|
175
|
-
key: "currentTime",
|
|
176
|
-
value
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
watch(duration, (value) => {
|
|
180
|
-
emitter.emit("update", {
|
|
181
|
-
id: toValue(id),
|
|
182
|
-
api: "media",
|
|
183
|
-
key: "duration",
|
|
184
|
-
value
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
watch(seeking, (value) => {
|
|
188
|
-
emitter.emit("update", {
|
|
189
|
-
id: toValue(id),
|
|
190
|
-
api: "media",
|
|
191
|
-
key: "seeking",
|
|
192
|
-
value
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
watch(volume, (value) => {
|
|
196
|
-
emitter.emit("update", {
|
|
197
|
-
id: toValue(id),
|
|
198
|
-
api: "media",
|
|
199
|
-
key: "volume",
|
|
200
|
-
value
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
watch(rate, (value) => {
|
|
204
|
-
emitter.emit("update", {
|
|
205
|
-
id: toValue(id),
|
|
206
|
-
api: "media",
|
|
207
|
-
key: "rate",
|
|
208
|
-
value
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
watch(waiting, (value) => {
|
|
212
|
-
emitter.emit("update", {
|
|
213
|
-
id: toValue(id),
|
|
214
|
-
api: "media",
|
|
215
|
-
key: "waiting",
|
|
216
|
-
value
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
watch(ended, (value) => {
|
|
220
|
-
emitter.emit("update", {
|
|
221
|
-
id: toValue(id),
|
|
222
|
-
api: "media",
|
|
223
|
-
key: "ended",
|
|
224
|
-
value
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
watch(playing, (value) => {
|
|
228
|
-
emitter.emit("update", {
|
|
229
|
-
id: toValue(id),
|
|
230
|
-
api: "media",
|
|
231
|
-
key: "playing",
|
|
232
|
-
value
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
watch(stalled, (value) => {
|
|
236
|
-
emitter.emit("update", {
|
|
237
|
-
id: toValue(id),
|
|
238
|
-
api: "media",
|
|
239
|
-
key: "stalled",
|
|
240
|
-
value
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
watch(buffered, (value) => {
|
|
244
|
-
emitter.emit("update", {
|
|
245
|
-
id: toValue(id),
|
|
246
|
-
api: "media",
|
|
247
|
-
key: "buffered",
|
|
248
|
-
value
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
watch(muted, (value) => {
|
|
252
|
-
emitter.emit("update", {
|
|
253
|
-
id: toValue(id),
|
|
254
|
-
api: "media",
|
|
255
|
-
key: "muted",
|
|
256
|
-
value
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
return {
|
|
260
|
-
currentTime,
|
|
261
|
-
remainingTime,
|
|
262
|
-
duration,
|
|
263
|
-
seeking,
|
|
264
|
-
volume,
|
|
265
|
-
rate,
|
|
266
|
-
waiting,
|
|
267
|
-
ended,
|
|
268
|
-
playing,
|
|
269
|
-
stalled,
|
|
270
|
-
buffered,
|
|
271
|
-
muted
|
|
272
|
-
};
|
|
273
126
|
}
|