changeset 338:2b374217d8a0

Merge pull request #42 from LucasThompson/fix/playhead-not-animating-if-playing-on-init Fix/playhead not animating if playing on init
author Lucas Thompson <LucasThompson@users.noreply.github.com>
date Fri, 19 May 2017 15:01:01 +0100
parents 802fbba26afe (current diff) 097d93b11445 (diff)
children 46435d5208e9 684619d3fad5
files
diffstat 1 files changed, 7 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/waveform/waveform.component.ts	Fri May 19 11:08:43 2017 +0100
+++ b/src/app/waveform/waveform.component.ts	Fri May 19 15:01:01 2017 +0100
@@ -145,22 +145,18 @@
       }
 
       this.seekedSubscription = this.audioService.seeked$.subscribe(() => {
-        if (!this.isPlaying) {
+        if (!this.audioService.isPlaying()) {
           this.animate();
         }
       });
       this.playingStateSubscription =
         this.audioService.playingStateChange$.subscribe(
           isPlaying => {
-            this.isPlaying = isPlaying;
-            if (this.isPlaying) {
+            if (isPlaying) {
               this.animate();
             }
           });
     } else {
-      if (this.isPlaying) {
-        this.isPlaying = false;
-      }
       if (this.playingStateSubscription) {
         this.playingStateSubscription.unsubscribe();
       }
@@ -197,7 +193,6 @@
   private playingStateSubscription: Subscription;
   private seekedSubscription: Subscription;
   private onAudioDataSubscription: Subscription;
-  private isPlaying: boolean;
   private zoomOnMouseDown: number;
   private offsetOnMouseDown: number;
   private hasShot: boolean;
@@ -227,7 +222,6 @@
     this.timeline = undefined;
     this.cursorLayer = undefined;
     this.highlightLayer = undefined;
-    this.isPlaying = false;
     this.isLoading = true;
   }
 
@@ -832,7 +826,7 @@
         const startTime = collected.startTime; // !!! + make use of
         const stepDuration = collected.stepDuration;
         const matrixData = collected.data;
-        
+
         if (matrixData.length === 0) {
           return;
         }
@@ -869,6 +863,7 @@
     this.isLoading = false;
     this.ref.markForCheck();
     this.timeline.tracks.update();
+    this.animate();
   }
 
   private animate(): void {
@@ -915,7 +910,7 @@
           this.timeline.tracks.update();
         }
 
-        if (this.isPlaying) {
+        if (this.audioService.isPlaying()) {
           requestAnimationFrame(updateSeekingCursor);
         }
       };
@@ -1089,13 +1084,13 @@
   if (isRegion) {
     return 'regions';
   }
-  throw 'No shape could be deduced';
+  throw new Error('No shape could be deduced');
 }
 
 function getCanonicalNoteLikeUnit(unit: string): NoteLikeUnit | null {
   const canonicalUnits: NoteLikeUnit[] = ['midi', 'hz'];
   return canonicalUnits.find(canonicalUnit => {
-    return unit.toLowerCase().indexOf(canonicalUnit) >= 0
+    return unit.toLowerCase().indexOf(canonicalUnit) >= 0;
   });
 }