@audiowalk/sdk
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -22,6 +22,6 @@ import { BehaviorSubject, Subject } from "rxjs"; | ||
readonly playing: import("rxjs").Observable<boolean>; | ||
private file?; | ||
private localStorage; | ||
constructor(playerElement: HTMLAudioElement, options?: PlayerControllerOptions); | ||
open(file: string, metadata: MediaMetadataInit): Promise<void>; | ||
open(file: string): Promise<void>; | ||
setMetadata(metadata: MediaMetadataInit): void; | ||
close(): void; | ||
@@ -28,0 +28,0 @@ play(): void; |
@@ -20,3 +20,2 @@ import { BehaviorSubject, combineLatest, map, Subject } from "rxjs"; | ||
playing = this.status.pipe(map((status) => status === "playing")); | ||
file; | ||
localStorage = new LocalStorage(); | ||
@@ -35,3 +34,3 @@ constructor(playerElement, options = {}) { | ||
// multiple times as part of a sequence and this is not the last call in that sequence. | ||
if (details.fastSeek !== true && details.seekTime) | ||
if (details.fastSeek !== true && details.seekTime !== undefined) | ||
this.seekTo(details.seekTime); | ||
@@ -72,3 +71,3 @@ }); | ||
navigator.mediaSession.setPositionState({ | ||
duration: this.playerElement.duration, | ||
duration: Number.isNaN(this.playerElement.duration) ? 0 : this.playerElement.duration, | ||
playbackRate: this.playerElement.playbackRate, | ||
@@ -84,6 +83,5 @@ position: this.playerElement.currentTime, | ||
} | ||
async open(file, metadata) { | ||
this.file = file; | ||
navigator.mediaSession.metadata = new MediaMetadata(metadata); | ||
const position = await this.localStorage.get(`progress-${this.file}`); | ||
async open(file) { | ||
this.playerElement.src = file; | ||
const position = await this.localStorage.get(`progress-${this.playerElement.src}`); | ||
if (position && this.options.autoSave) | ||
@@ -94,4 +92,6 @@ this.playerElement.currentTime = parseFloat(position); | ||
} | ||
setMetadata(metadata) { | ||
navigator.mediaSession.metadata = new MediaMetadata(metadata); | ||
} | ||
close() { | ||
this.file = undefined; | ||
this.playerElement.pause(); | ||
@@ -107,3 +107,3 @@ this.playerElement.src = ""; | ||
play() { | ||
if (!this.file) | ||
if (!this.playerElement.src) | ||
throw new Error("No file opened"); | ||
@@ -114,3 +114,3 @@ this.log("Called play"); | ||
pause() { | ||
if (!this.file) | ||
if (!this.playerElement.src) | ||
throw new Error("No file opened"); | ||
@@ -121,3 +121,3 @@ this.log("Called pause"); | ||
seekTo(seconds) { | ||
if (!this.file) | ||
if (!this.playerElement.src) | ||
throw new Error("No file opened"); | ||
@@ -128,3 +128,3 @@ this.log("Called seekTo"); | ||
back(seconds = 10) { | ||
if (!this.file) | ||
if (!this.playerElement.src) | ||
throw new Error("No file opened"); | ||
@@ -135,3 +135,3 @@ const position = this.playerElement.currentTime; | ||
forward(seconds = 10) { | ||
if (!this.file) | ||
if (!this.playerElement.src) | ||
throw new Error("No file opened"); | ||
@@ -143,5 +143,5 @@ const position = this.playerElement.currentTime; | ||
async savePosition(currentTime) { | ||
if (!this.file) | ||
if (!this.playerElement.src) | ||
return; | ||
await this.localStorage.set(`progress-${this.file}`, String(currentTime)); | ||
await this.localStorage.set(`progress-${this.playerElement.src}`, String(currentTime)); | ||
} | ||
@@ -148,0 +148,0 @@ log(message) { |
{ | ||
"name": "@audiowalk/sdk", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
10913