changeset 82:1bd1a44f5dd3

Add method for seeking to specific time to the audio player service
author Lucas Thompson <dev@lucas.im>
date Thu, 23 Feb 2017 15:42:59 +0000
parents 13955649f5af
children 57d8600f86ab
files src/app/services/audio-player/audio-player.service.ts
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/services/audio-player/audio-player.service.ts	Wed Feb 22 18:09:50 2017 +0000
+++ b/src/app/services/audio-player/audio-player.service.ts	Thu Feb 23 15:42:59 2017 +0000
@@ -44,6 +44,7 @@
     this.currentObjectUrl = url;
     this.audioElement.pause();
     this.audioElement.src = url;
+    this.audioElement.load();
   }
 
   togglePlaying(): void {
@@ -57,6 +58,16 @@
     this.audioElement.volume = value; // TODO check bounds?
   }
 
+  seekTo(seconds: number): void {
+    if (seconds < 0) {
+      this.audioElement.currentTime = 0;
+    } else if (seconds < this.getDuration()) {
+      this.audioElement.currentTime = seconds;
+    } else {
+      this.audioElement.currentTime = this.getDuration();
+    }
+  }
+
   seekBy(seconds: number): void {
     // TODO some kind of error handling?
     this.audioElement.currentTime += seconds;