more bugfixes

This commit is contained in:
Djkato 2023-07-20 20:34:34 +02:00
parent 84fb83480a
commit 044e38ccf1
4 changed files with 18 additions and 15 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@euterpe.js/euterpe", "name": "@euterpe.js/euterpe",
"version": "1.0.5", "version": "1.0.8",
"type": "module", "type": "module",
"description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!", "description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!",
"main": "./src/index.js", "main": "./src/index.js",

View file

@ -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")) 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)! 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) => { this.try_play_async().then((s) => {
if (this.current_song) this.played_history.push(this.current_song) 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! 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)! 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) => { this.try_play_async().then((s) => {
if (this.current_song) this.played_history.push(this.current_song) 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! 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)! 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() this.play()
if (this.current_song) this.played_history.push(this.current_song) if (this.current_song) this.played_history.push(this.current_song)
this.current_song = new_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") 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)! 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() this.play()
if (this.current_song) this.played_history.push(this.current_song) if (this.current_song) this.played_history.push(this.current_song)
this.current_song = new_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) 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`)) if (!new_song) reject(new Error(`No song with id "${new_song_id}" found`))
else { 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) => { this.try_play_async().then((s) => {
if (this.current_song) this.played_history.push(this.current_song) 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) 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`)) if (!new_song) reject(new Error(`No song with id "${new_song_id}" found`))
else { 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) => { this.play_async().then((s) => {
if (this.current_song) this.played_history.push(this.current_song) 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) 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`) if (!new_song) throw new Error(`No song with id "${new_song_id}" found`)
else { else {
this.new_song(new_song.url.href) this.new_song(new_song.url.toString())
this.play() this.play()
if (this.current_song) this.played_history.push(this.current_song) if (this.current_song) this.played_history.push(this.current_song)
this.current_song = new_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")) 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)! 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) => { this.try_play_async().then((s) => {
//if (this.current_song) this.played_history.push(this.current_song) //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! 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)! 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) => { this.try_play_async().then((s) => {
//if (this.current_song) this.played_history.push(this.current_song) //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") 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)! 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() this.play()
//if (this.current_song) this.played_history.push(this.current_song) //if (this.current_song) this.played_history.push(this.current_song)
this.current_song_id = new_song.id! 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! 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)! 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() this.play()
//if (this.current_song) this.played_history.push(this.current_song) //if (this.current_song) this.played_history.push(this.current_song)
this.current_song_id = new_song.id! this.current_song_id = new_song.id!

View file

@ -1,6 +1,6 @@
{ {
"name": "@euterpe.js/player", "name": "@euterpe.js/player",
"version": "1.0.23", "version": "1.0.4",
"type": "module", "type": "module",
"description": "A simple, safe AudioContext web music player", "description": "A simple, safe AudioContext web music player",
"main": "./src/index.js", "main": "./src/index.js",

View file

@ -162,7 +162,8 @@ export class MusicPlayer {
try_play_toggle_async() { try_play_toggle_async() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") { 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) { if (this.audio_element.paused) {
this.audio_element.play().then((s) => { this.audio_element.play().then((s) => {
@ -224,7 +225,8 @@ export class MusicPlayer {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (this.is_playing) reject(Error("Already playing")) if (this.is_playing) reject(Error("Already playing"))
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") { 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.audio_element.play().then((s) => {
this.is_playing = true this.is_playing = true
@ -276,6 +278,7 @@ export class MusicPlayer {
try_new_song_async(path: string) { try_new_song_async(path: string) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.audio_element.src = this.current_song_path = path 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! //Found out today about this. Such a nice new way to mass remove event listeners!
const controller = new AbortController(); const controller = new AbortController();