From 044e38ccf11a7e67b4b6f496ac79c9c51f1aaaf4 Mon Sep 17 00:00:00 2001 From: Djkato Date: Thu, 20 Jul 2023 20:34:34 +0200 Subject: [PATCH] more bugfixes --- packages/euterpe/package.json | 2 +- packages/euterpe/src/index.ts | 22 +++++++++++----------- packages/player/package.json | 2 +- packages/player/src/index.ts | 7 +++++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/euterpe/package.json b/packages/euterpe/package.json index d1703f4..fb29ac2 100644 --- a/packages/euterpe/package.json +++ b/packages/euterpe/package.json @@ -1,6 +1,6 @@ { "name": "@euterpe.js/euterpe", - "version": "1.0.5", + "version": "1.0.8", "type": "module", "description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!", "main": "./src/index.js", diff --git a/packages/euterpe/src/index.ts b/packages/euterpe/src/index.ts index c2fca19..9816a8b 100644 --- a/packages/euterpe/src/index.ts +++ b/packages/euterpe/src/index.ts @@ -54,7 +54,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == this.db.songs.length) reject(new Error("Won't go past the last song")) new_song = this.db.songs.find((song) => song.id == next_id)! } - this.try_new_song_async(new_song.url.href).then( + this.try_new_song_async(new_song.url.toString()).then( () => { this.try_play_async().then((s) => { if (this.current_song) this.played_history.push(this.current_song) @@ -85,7 +85,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == this.db.songs.length) next_id = this.db.songs[0].id! new_song = this.db.songs.find((song) => song.id == next_id)! } - this.try_new_song_async(new_song.url.href).then( + this.try_new_song_async(new_song.url.toString()).then( () => { this.try_play_async().then((s) => { if (this.current_song) this.played_history.push(this.current_song) @@ -114,7 +114,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == this.db.songs.length) next_id = this.db.songs[0].id! new_song = this.db.songs.find((song) => song.id == next_id)! } - this.new_song(new_song.url.href) + this.new_song(new_song.url.toString()) this.play() if (this.current_song) this.played_history.push(this.current_song) this.current_song = new_song @@ -135,7 +135,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == this.db.songs.length) throw new Error("Won't go past the last song") new_song = this.db.songs.find((song) => song.id == next_id)! } - this.new_song(new_song.url.href) + this.new_song(new_song.url.toString()) this.play() if (this.current_song) this.played_history.push(this.current_song) this.current_song = new_song @@ -149,7 +149,7 @@ class Euterpe extends Player.MusicPlayer { const new_song = this.db.songs.find((song) => song.id! == new_song_id) if (!new_song) reject(new Error(`No song with id "${new_song_id}" found`)) else { - this.try_new_song_async(new_song.url.href).then( + this.try_new_song_async(new_song.url.toString()).then( () => { this.try_play_async().then((s) => { if (this.current_song) this.played_history.push(this.current_song) @@ -171,7 +171,7 @@ class Euterpe extends Player.MusicPlayer { const new_song = this.db.songs.find((song) => song.id! == new_song_id) if (!new_song) reject(new Error(`No song with id "${new_song_id}" found`)) else { - this.try_new_song_async(new_song.url.href).then( + this.try_new_song_async(new_song.url.toString()).then( () => { this.play_async().then((s) => { if (this.current_song) this.played_history.push(this.current_song) @@ -192,7 +192,7 @@ class Euterpe extends Player.MusicPlayer { const new_song = this.db.songs.find((song) => song.id! == new_song_id) if (!new_song) throw new Error(`No song with id "${new_song_id}" found`) else { - this.new_song(new_song.url.href) + this.new_song(new_song.url.toString()) this.play() if (this.current_song) this.played_history.push(this.current_song) this.current_song = new_song @@ -216,7 +216,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == this.db.songs.length) reject(new Error("Won't roll backwards to last song")) new_song = this.db.songs.find((song) => song.id == next_id)! } - this.try_new_song_async(new_song.url.href).then( + this.try_new_song_async(new_song.url.toString()).then( () => { this.try_play_async().then((s) => { //if (this.current_song) this.played_history.push(this.current_song) @@ -247,7 +247,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == -1) next_id = this.db.songs[this.db.songs.length - 1].id! new_song = this.db.songs.find((song) => song.id == next_id)! } - this.try_new_song_async(new_song.url.href).then( + this.try_new_song_async(new_song.url.toString()).then( () => { this.try_play_async().then((s) => { //if (this.current_song) this.played_history.push(this.current_song) @@ -276,7 +276,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == this.db.songs.length) throw new Error("Won't go past the last song") new_song = this.db.songs.find((song) => song.id == next_id)! } - this.new_song(new_song.url.href) + this.new_song(new_song.url.toString()) this.play() //if (this.current_song) this.played_history.push(this.current_song) this.current_song_id = new_song.id! @@ -298,7 +298,7 @@ class Euterpe extends Player.MusicPlayer { if (next_id == this.db.songs.length) next_id = this.db.songs[this.db.songs.length].id! new_song = this.db.songs.find((song) => song.id == next_id)! } - this.new_song(new_song.url.href) + this.new_song(new_song.url.toString()) this.play() //if (this.current_song) this.played_history.push(this.current_song) this.current_song_id = new_song.id! diff --git a/packages/player/package.json b/packages/player/package.json index 3a2a0a6..c85b403 100644 --- a/packages/player/package.json +++ b/packages/player/package.json @@ -1,6 +1,6 @@ { "name": "@euterpe.js/player", - "version": "1.0.23", + "version": "1.0.4", "type": "module", "description": "A simple, safe AudioContext web music player", "main": "./src/index.js", diff --git a/packages/player/src/index.ts b/packages/player/src/index.ts index 12ceb74..dc58d25 100644 --- a/packages/player/src/index.ts +++ b/packages/player/src/index.ts @@ -162,7 +162,8 @@ export class MusicPlayer { try_play_toggle_async() { return new Promise((resolve, reject) => { if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") { - reject("Context closed or suspended") + this.audio_context.resume().then(undefined, (e) => + reject("Context closed or suspended" + e)) } if (this.audio_element.paused) { this.audio_element.play().then((s) => { @@ -224,7 +225,8 @@ export class MusicPlayer { return new Promise((resolve, reject) => { if (this.is_playing) reject(Error("Already playing")) if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") { - reject("Context closed or suspended") + this.audio_context.resume().then(undefined, (e) => + reject("Context closed or suspended" + e)) } this.audio_element.play().then((s) => { this.is_playing = true @@ -276,6 +278,7 @@ export class MusicPlayer { try_new_song_async(path: string) { return new Promise((resolve, reject) => { this.audio_element.src = this.current_song_path = path + this.current_song_duration = this.audio_element.duration //Found out today about this. Such a nice new way to mass remove event listeners! const controller = new AbortController();