@audiowalk/sdk 1.2.1 → 1.3.0

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.
@@ -19,10 +19,10 @@ export declare class PlayerController {
19
19
  readonly progress: import("rxjs").Observable<number>;
20
20
  readonly status: BehaviorSubject<PlayerStatus | null>;
21
21
  readonly playing: import("rxjs").Observable<boolean>;
22
- private file?;
23
22
  private localStorage;
24
23
  constructor(playerElement: HTMLAudioElement, options?: PlayerControllerOptions);
25
- open(file: string, metadata: MediaMetadataInit): Promise<void>;
24
+ open(file: string): Promise<void>;
25
+ setMetadata(metadata: MediaMetadataInit): void;
26
26
  close(): void;
27
27
  play(): void;
28
28
  pause(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"player-controller.d.ts","sourceRoot":"","sources":["../../src/player/player-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAsB,OAAO,EAAE,MAAM,MAAM,CAAC;AAGpE,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,oBAAY,YAAY;IACtB,SAAS,YAAY;IACrB,QAAQ,WAAW;IACnB,OAAO,UAAU;CAClB;AAED,qBAAa,gBAAgB;IAmBf,OAAO,CAAC,QAAQ,CAAC,aAAa;IAAoB,OAAO,CAAC,OAAO;IAlB7E,SAAgB,MAAM,gBAAuB;IAC7C,SAAgB,OAAO,gBAAuB;IAC9C,SAAgB,MAAM,gBAAuB;IAE7C,SAAgB,WAAW,0BAAkC;IAC7D,SAAgB,SAAS,0BAAkC;IAC3D,SAAgB,QAAQ,oCAEtB;IAEF,SAAgB,MAAM,uCAAkD;IAExE,SAAgB,OAAO,qCAA2D;IAElF,OAAO,CAAC,IAAI,CAAC,CAAS;IAEtB,OAAO,CAAC,YAAY,CAAsB;gBAEb,aAAa,EAAE,gBAAgB,EAAU,OAAO,GAAE,uBAA4B;IAmErG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C,GAAG;CAOZ"}
@@ -17,7 +17,6 @@ export class PlayerController {
17
17
  progress = combineLatest([this.currentTime, this.totalTime]).pipe(map(([currentTime, totalTime]) => currentTime / totalTime));
18
18
  status = new BehaviorSubject(null);
19
19
  playing = this.status.pipe(map((status) => status === "playing"));
20
- file;
21
20
  localStorage = new LocalStorage();
22
21
  constructor(playerElement, options = {}) {
23
22
  this.playerElement = playerElement;
@@ -31,7 +30,7 @@ export class PlayerController {
31
30
  navigator.mediaSession.setActionHandler("seekto", (details) => {
32
31
  // The fastSeek dictionary member will be true if the seek action is being called
33
32
  // multiple times as part of a sequence and this is not the last call in that sequence.
34
- if (details.fastSeek !== true && details.seekTime)
33
+ if (details.fastSeek !== true && details.seekTime !== undefined)
35
34
  this.seekTo(details.seekTime);
36
35
  });
37
36
  this.status.subscribe((status) => {
@@ -67,7 +66,7 @@ export class PlayerController {
67
66
  });
68
67
  this.playerElement.addEventListener("timeupdate", () => {
69
68
  navigator.mediaSession.setPositionState({
70
- duration: this.playerElement.duration,
69
+ duration: Number.isNaN(this.playerElement.duration) ? 0 : this.playerElement.duration,
71
70
  playbackRate: this.playerElement.playbackRate,
72
71
  position: this.playerElement.currentTime,
73
72
  });
@@ -78,17 +77,18 @@ export class PlayerController {
78
77
  this.savePosition(this.playerElement.currentTime);
79
78
  });
80
79
  }
81
- async open(file, metadata) {
82
- this.file = file;
83
- navigator.mediaSession.metadata = new MediaMetadata(metadata);
84
- const position = await this.localStorage.get(`progress-${this.file}`);
80
+ async open(file) {
81
+ this.playerElement.src = file;
82
+ const position = await this.localStorage.get(`progress-${this.playerElement.src}`);
85
83
  if (position && this.options.autoSave)
86
84
  this.playerElement.currentTime = parseFloat(position);
87
85
  if (this.options.playOnInit)
88
86
  await this.playerElement.play();
89
87
  }
88
+ setMetadata(metadata) {
89
+ navigator.mediaSession.metadata = new MediaMetadata(metadata);
90
+ }
90
91
  close() {
91
- this.file = undefined;
92
92
  this.playerElement.pause();
93
93
  this.playerElement.src = "";
94
94
  navigator.mediaSession.setActionHandler("play", null);
@@ -99,40 +99,40 @@ export class PlayerController {
99
99
  navigator.mediaSession.metadata = null;
100
100
  }
101
101
  play() {
102
- if (!this.file)
102
+ if (!this.playerElement.src)
103
103
  throw new Error("No file opened");
104
104
  this.log("Called play");
105
105
  this.playerElement?.play();
106
106
  }
107
107
  pause() {
108
- if (!this.file)
108
+ if (!this.playerElement.src)
109
109
  throw new Error("No file opened");
110
110
  this.log("Called pause");
111
111
  this.playerElement?.pause();
112
112
  }
113
113
  seekTo(seconds) {
114
- if (!this.file)
114
+ if (!this.playerElement.src)
115
115
  throw new Error("No file opened");
116
116
  this.log("Called seekTo");
117
117
  this.playerElement.currentTime = seconds;
118
118
  }
119
119
  back(seconds = 10) {
120
- if (!this.file)
120
+ if (!this.playerElement.src)
121
121
  throw new Error("No file opened");
122
122
  const position = this.playerElement.currentTime;
123
123
  this.seekTo(Math.max(position - seconds, 0));
124
124
  }
125
125
  forward(seconds = 10) {
126
- if (!this.file)
126
+ if (!this.playerElement.src)
127
127
  throw new Error("No file opened");
128
128
  const position = this.playerElement.currentTime;
129
129
  const duration = this.playerElement.duration;
130
130
  this.seekTo(duration && duration > 0 ? Math.min(position + seconds, duration) : position + seconds);
131
131
  }
132
132
  async savePosition(currentTime) {
133
- if (!this.file)
133
+ if (!this.playerElement.src)
134
134
  return;
135
- await this.localStorage.set(`progress-${this.file}`, String(currentTime));
135
+ await this.localStorage.set(`progress-${this.playerElement.src}`, String(currentTime));
136
136
  }
137
137
  log(message) {
138
138
  const time = this.playerElement?.currentTime ? Math.round(this.playerElement?.currentTime) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audiowalk/sdk",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/audiowalk-cz/components.git"