@eluvio/elv-player-js 1.0.78 → 1.0.79

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": "@eluvio/elv-player-js",
3
- "version": "1.0.78",
3
+ "version": "1.0.79",
4
4
  "description": "![Eluvio Logo](src/static/images/Logo.png \"Eluvio Logo\")",
5
5
  "main": "src/index.js",
6
6
  "license": "MIT",
@@ -159,6 +159,98 @@ class PlayerControls {
159
159
  });
160
160
  }
161
161
 
162
+
163
+ AutohideControls(controls) {
164
+ this.video.addEventListener("play", () => {
165
+ this.played = true;
166
+ });
167
+
168
+ const PlayerOut = () => {
169
+ if(!this.played && this.video.paused) { return; }
170
+
171
+ this.FadeOut("controls", [controls, this.settingsMenu, this.toolTip], 2000);
172
+ };
173
+
174
+ const PlayerMove = () => {
175
+ if(this.controlsHover) { return; }
176
+
177
+ this.FadeIn("controls", [controls, this.settingsMenu, this.toolTip]);
178
+ this.FadeOut("controls", [controls, this.settingsMenu, this.toolTip], 3000, () => this.target.style.cursor = "none");
179
+
180
+ this.target.style.cursor = "unset";
181
+ };
182
+
183
+ const ControlsIn = () => {
184
+ clearTimeout(this.timeouts.controls);
185
+ this.controlsHover = true;
186
+ };
187
+
188
+ const ControlsOut = () => this.controlsHover = false;
189
+
190
+ // Play / Pause
191
+ this.video.addEventListener("play", () => PlayerMove);
192
+ this.video.addEventListener("pause", () => PlayerMove);
193
+
194
+ // Mouse events
195
+ this.target.addEventListener("mousemove", PlayerMove);
196
+ this.target.addEventListener("mouseleave", PlayerOut);
197
+ controls.addEventListener("mouseenter", ControlsIn);
198
+ controls.addEventListener("mouseleave", ControlsOut);
199
+
200
+ if(this.settingsMenu) {
201
+ this.settingsMenu.addEventListener("mouseenter", ControlsIn);
202
+ this.settingsMenu.addEventListener("mouseleave", ControlsOut);
203
+ }
204
+
205
+ if(this.toolTip) {
206
+ this.toolTip.addEventListener("mouseenter", ControlsIn);
207
+ this.toolTip.addEventListener("mouseleave", ControlsOut);
208
+ }
209
+
210
+ // Touch events
211
+ this.target.addEventListener("touchmove", PlayerMove);
212
+ this.target.addEventListener("touchleave", PlayerOut);
213
+ controls.addEventListener("touchmove", ControlsIn);
214
+ controls.addEventListener("touchleave", ControlsOut);
215
+ controls.addEventListener("touchend", () => { ControlsOut(); PlayerOut(); });
216
+
217
+ if(this.settingsMenu) {
218
+ this.settingsMenu.addEventListener("touchmove", ControlsIn);
219
+ this.settingsMenu.addEventListener("touchleave", ControlsOut);
220
+ this.settingsMenu.addEventListener("touchend", () => {
221
+ ControlsOut();
222
+ PlayerOut();
223
+ });
224
+ }
225
+
226
+ if(this.toolTip) {
227
+ this.toolTip.addEventListener("touchmove", ControlsIn);
228
+ this.toolTip.addEventListener("touchleave", ControlsOut);
229
+ this.toolTip.addEventListener("touchend", () => {
230
+ ControlsOut();
231
+ PlayerOut();
232
+ });
233
+ }
234
+
235
+ // Keyboard events
236
+ this.target.addEventListener("blur", () => setTimeout(() => {
237
+ if(!this.target.contains(document.activeElement)) {
238
+ PlayerOut();
239
+ ControlsOut();
240
+ }
241
+ }), 2000);
242
+
243
+ window.addEventListener("blur", () => { PlayerOut(); ControlsOut(); });
244
+
245
+ Array.from(this.target.querySelectorAll("button, input")).forEach(button => {
246
+ button.addEventListener("focus", () => { PlayerMove(); ControlsIn(); });
247
+ });
248
+
249
+ if(!this.controlsHover) {
250
+ PlayerOut();
251
+ }
252
+ }
253
+
162
254
  InitializeControls() {
163
255
  this.target.setAttribute("tabindex", "0");
164
256
 
@@ -208,11 +300,8 @@ class PlayerControls {
208
300
 
209
301
  */
210
302
 
211
- if(
212
- this.playerOptions.controls === EluvioPlayerParameters.controls.DEFAULT ||
213
- this.playerOptions.controls === EluvioPlayerParameters.controls.OFF
214
- ) {
215
- // Controls disabled
303
+ if(this.playerOptions.controls === EluvioPlayerParameters.controls.DEFAULT) {
304
+ // Default controls
216
305
  return;
217
306
  }
218
307
 
@@ -226,6 +315,53 @@ class PlayerControls {
226
315
  this.timeouts.playPause = setTimeout(() => this.video.paused ? this.video.play() : this.video.pause(), 200);
227
316
  });
228
317
 
318
+ if(this.playerOptions.controls === EluvioPlayerParameters.controls.OFF) {
319
+ // Controls hidden but need to show volume controls
320
+
321
+ let controlsCreated = false;
322
+ const CreateVolumeControl = () => {
323
+ if(controlsCreated) { return; }
324
+
325
+ controlsCreated = true;
326
+ const controls = CreateElement({
327
+ parent: this.target,
328
+ type: "div",
329
+ classes: ["eluvio-player__hidden-audio-controls"]
330
+ });
331
+
332
+ const volumeButton = CreateImageButton({
333
+ parent: controls,
334
+ svg: this.video.muted || this.video.volume === 0 ? MutedIcon : (this.video.volume < 0.5 ? VolumeLowIcon : VolumeHighIcon),
335
+ classes: ["eluvio-player__controls__button--fixed-size"],
336
+ label: this.video.muted ? "Unmute" : "Mute"
337
+ });
338
+
339
+ volumeButton.addEventListener("click", () => {
340
+ this.video.muted = !this.video.muted;
341
+ });
342
+
343
+ this.video.addEventListener("volumechange", () => {
344
+ volumeButton.innerHTML = this.video.muted || this.video.volume === 0 ? MutedIcon : (this.video.volume < 0.5 ? VolumeLowIcon : VolumeHighIcon);
345
+ });
346
+
347
+ this.AutohideControls(controls);
348
+ };
349
+
350
+ const HasAudio = () => (this.video.mozHasAudio || Boolean(this.video.webkitAudioDecodedByteCount) || Boolean(this.video.audioTracks && this.video.audioTracks.length));
351
+
352
+ if(HasAudio()) {
353
+ CreateVolumeControl();
354
+ } else {
355
+ this.video.addEventListener("loadeddata", function() {
356
+ if(HasAudio()) {
357
+ CreateVolumeControl();
358
+ }
359
+ });
360
+ }
361
+
362
+ return;
363
+ }
364
+
229
365
  // Big play icon
230
366
  this.bigPlayButton = CreateImageButton({
231
367
  parent: this.target,
@@ -245,10 +381,6 @@ class PlayerControls {
245
381
  this.bigPlayButton.style.display = this.video.paused ? null : "none";
246
382
  this.bigPlayButton.addEventListener("click", () => this.video.play());
247
383
 
248
- if(this.playerOptions.controls === EluvioPlayerParameters.controls.OFF) {
249
- return;
250
- }
251
-
252
384
  // Controls container
253
385
  const controls = CreateElement({
254
386
  parent: this.target,
@@ -482,8 +614,6 @@ class PlayerControls {
482
614
  controls.addEventListener("dblclick", event => event.stopPropagation());
483
615
 
484
616
  this.video.addEventListener("play", () => {
485
- this.played = true;
486
-
487
617
  playPauseButton.innerHTML = PauseIcon;
488
618
  playPauseButton.classList.add("eluvio-player__controls__button-pause");
489
619
  playPauseButton.setAttribute("aria-label", "Pause");
@@ -523,70 +653,8 @@ class PlayerControls {
523
653
  }
524
654
  });
525
655
 
526
- // Autohide controls
527
656
  if(this.playerOptions.controls === EluvioPlayerParameters.controls.AUTO_HIDE) {
528
- const PlayerOut = () => {
529
- if(!this.played) { return; }
530
-
531
- this.FadeOut("controls", [controls, this.settingsMenu, this.toolTip], 2000);
532
- };
533
-
534
- const PlayerMove = () => {
535
- if(this.controlsHover) { return; }
536
-
537
- this.FadeIn("controls", [controls, this.settingsMenu, this.toolTip]);
538
- this.FadeOut("controls", [controls, this.settingsMenu, this.toolTip], 3000, () => this.target.style.cursor = "none");
539
-
540
- this.target.style.cursor = "unset";
541
- };
542
-
543
- const ControlsIn = () => {
544
- clearTimeout(this.timeouts.controls);
545
- this.controlsHover = true;
546
- };
547
-
548
- const ControlsOut = () => this.controlsHover = false;
549
-
550
- // Play / Pause
551
- this.video.addEventListener("play", () => PlayerMove);
552
- this.video.addEventListener("pause", () => PlayerMove);
553
-
554
- // Mouse events
555
- this.target.addEventListener("mousemove", PlayerMove);
556
- this.target.addEventListener("mouseleave", PlayerOut);
557
- controls.addEventListener("mouseenter", ControlsIn);
558
- controls.addEventListener("mouseleave", ControlsOut);
559
- this.settingsMenu.addEventListener("mouseenter", ControlsIn);
560
- this.settingsMenu.addEventListener("mouseleave", ControlsOut);
561
- this.toolTip.addEventListener("mouseenter", ControlsIn);
562
- this.toolTip.addEventListener("mouseleave", ControlsOut);
563
-
564
- // Touch events
565
- this.target.addEventListener("touchmove", PlayerMove);
566
- this.target.addEventListener("touchleave", PlayerOut);
567
- controls.addEventListener("touchmove", ControlsIn);
568
- controls.addEventListener("touchleave", ControlsOut);
569
- controls.addEventListener("touchend", () => { ControlsOut(); PlayerOut(); });
570
- this.settingsMenu.addEventListener("touchmove", ControlsIn);
571
- this.settingsMenu.addEventListener("touchleave", ControlsOut);
572
- this.settingsMenu.addEventListener("touchend", () => { ControlsOut(); PlayerOut(); });
573
- this.toolTip.addEventListener("touchmove", ControlsIn);
574
- this.toolTip.addEventListener("touchleave", ControlsOut);
575
- this.toolTip.addEventListener("touchend", () => { ControlsOut(); PlayerOut(); });
576
-
577
- // Keyboard events
578
- this.target.addEventListener("blur", () => setTimeout(() => {
579
- if(!this.target.contains(document.activeElement)) {
580
- PlayerOut();
581
- ControlsOut();
582
- }
583
- }), 2000);
584
-
585
- window.addEventListener("blur", () => { PlayerOut(); ControlsOut(); });
586
-
587
- Array.from(this.target.querySelectorAll("button, input")).forEach(button => {
588
- button.addEventListener("focus", () => { PlayerMove(); ControlsIn(); });
589
- });
657
+ this.AutohideControls(controls);
590
658
  }
591
659
  }
592
660
 
package/src/index.js CHANGED
@@ -481,7 +481,7 @@ export class EluvioPlayer {
481
481
  parent: this.target,
482
482
  type: "video",
483
483
  options: {
484
- muted: this.playerOptions.muted !== EluvioPlayerParameters.muted.OFF,
484
+ muted: [EluvioPlayerParameters.muted.OFF, EluvioPlayerParameters.muted.WHEN_NOT_VISIBLE].includes(this.playerOptions.muted),
485
485
  controls: this.playerOptions.controls === EluvioPlayerParameters.controls.DEFAULT,
486
486
  loop: this.playerOptions.loop === EluvioPlayerParameters.loop.ON
487
487
  },
@@ -154,6 +154,22 @@ $button-height: 35px;
154
154
  z-index: 10;
155
155
  }
156
156
 
157
+ &__hidden-audio-controls {
158
+ bottom: 5px;
159
+ height: max-content;
160
+ left: 5px;
161
+ opacity: 1;
162
+ position: absolute;
163
+ transition: opacity 0.25s linear;
164
+ width: max-content;
165
+
166
+ button {
167
+ background: $controls-color;
168
+ border-radius: 100%;
169
+ padding: $controls-padding;
170
+ }
171
+ }
172
+
157
173
  &__controls {
158
174
  align-items: center;
159
175
  background: $controls-color;
@@ -575,11 +591,13 @@ $button-height: 35px;
575
591
  }
576
592
 
577
593
  .eluvio-player__controls__button {
578
- height: CALC(#{$button-height} * 0.9);
579
- max-height: CALC(#{$button-height} * 0.9);
580
- max-width: CALC(#{$button-height} * 0.9);
581
- min-height: CALC(#{$button-height} * 0.9);
582
- min-width: CALC(#{$button-height} * 0.9);
594
+ &:not(&--fixed-size) {
595
+ height: CALC(#{$button-height} * 0.9);
596
+ max-height: CALC(#{$button-height} * 0.9);
597
+ max-width: CALC(#{$button-height} * 0.9);
598
+ min-height: CALC(#{$button-height} * 0.9);
599
+ min-width: CALC(#{$button-height} * 0.9);
600
+ }
583
601
  }
584
602
 
585
603
  .eluvio-player__controls__volume-container {