From c2aeeb804f84051c3a3f650f21635e126a533cad Mon Sep 17 00:00:00 2001
From: jojohoch <joachim.hoch@iqb.hu-berlin.de>
Date: Thu, 25 Nov 2021 09:00:50 +0100
Subject: [PATCH] [player] Initialize delays on audios after dependencies are
 dissolved

Hint and autostart functionality of videos and audios is initialized
only after dependencies to other audios and videos have been resolved.
This prevents the hint of an audio and video from starting, although
the audio is not yet enabled.
---
 .../control-bar/control-bar.component.ts      | 29 +++++++++++--------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/projects/common/element-components/control-bar/control-bar.component.ts b/projects/common/element-components/control-bar/control-bar.component.ts
index 510f87f98..af8faa3ee 100644
--- a/projects/common/element-components/control-bar/control-bar.component.ts
+++ b/projects/common/element-components/control-bar/control-bar.component.ts
@@ -37,7 +37,6 @@ export class ControlBarComponent implements OnInit, OnChanges, OnDestroy {
   // TODO:
   // uninterruptible: boolean; // false kein Blättern; starten eines anderen Videos; ....
   // hideOtherPages: boolean; // false (Solange nicht vollständig gespielt, sind alle anderen Seiten verborgen)
-  // minRuns: number; // 1
 
   ngOnInit(): void {
     this.dependencyDissolved = !this.elementModel.activeAfterID;
@@ -74,9 +73,8 @@ export class ControlBarComponent implements OnInit, OnChanges, OnDestroy {
   }
 
   ngOnChanges(changes: SimpleChanges): void {
-    if (changes.project && changes.project.currentValue === 'player') {
-      this.initAutostart();
-      this.initHint();
+    if ((changes.project || changes.dependencyDissolved) && this.project === 'player') {
+      this.initDelays();
     }
   }
 
@@ -123,10 +121,18 @@ export class ControlBarComponent implements OnInit, OnChanges, OnDestroy {
     return this.disabled;
   }
 
+  private initDelays(): void {
+    if (!this.started &&
+      (this.dependencyDissolved || this.dependencyDissolved === undefined)) {
+      this.initAutostart();
+      this.initHint();
+    }
+  }
+
   private initAutostart(): void {
-    if (this.elementModel.autostart && !this.started) {
+    if (this.elementModel.autostart) {
       setTimeout(() => {
-        if (!this.started) {
+        if (!this.started && this.dependencyDissolved) {
           this._play();
         }
       }, this.elementModel.autostartDelay);
@@ -134,9 +140,9 @@ export class ControlBarComponent implements OnInit, OnChanges, OnDestroy {
   }
 
   private initHint(): void {
-    if (this.elementModel.hintLabel && !this.started) {
+    if (this.elementModel.hintLabel) {
       setTimeout(() => {
-        if (!this.started) {
+        if (!this.started && this.dependencyDissolved) {
           this.showHint = true;
         }
       }, this.elementModel.hintLabelDelay);
@@ -144,10 +150,9 @@ export class ControlBarComponent implements OnInit, OnChanges, OnDestroy {
   }
 
   private _play(): void {
-    this.player.play().then(() => {
-    },
-    // eslint-disable-next-line no-console
-    () => console.error('player: cannot play this media file'));
+    this.player.play().then(() => {},
+      // eslint-disable-next-line no-console
+      () => console.error('player: cannot play this media file'));
   }
 
   private sendPlaybackTimeChanged() {
-- 
GitLab