@euterpe.js/player
Advanced tools
Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "@euterpe.js/player", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "A simple, safe AudioContext web music player", |
@@ -31,2 +31,5 @@ export declare enum SubscribeEvents { | ||
try_seek_async(new_time: number): Promise<unknown>; | ||
/** | ||
* Unsafe, throws error if failed. Use try_seek_async or seek_async unless you don't care about the result. | ||
*/ | ||
seek(new_time: number): void; | ||
@@ -33,0 +36,0 @@ /** |
@@ -123,32 +123,13 @@ var _MusicPlayer_instances, _MusicPlayer_volume_cache, _MusicPlayer_pub_sub, _MusicPlayer_emit_time, _MusicPlayer_emit_duration_fmt, _MusicPlayer_emit_time_fmt, _MusicPlayerBuilder_audio_context, _MusicPlayerBuilder_gain, _MusicPlayerBuilder_track, _MusicPlayerBuilder_volume, _MusicPlayerBuilder_prev_node, _MusicPlayerBuilder_is_gain_connected; | ||
this.is_playing = false; | ||
reject("Can't seek - track not playing"); | ||
reject(new Error("Can't seek - track not playing")); | ||
} | ||
this.audio_element.currentTime = new_time; | ||
resolve(null); | ||
/*audio_element.play().then((s) => resolve(s), (r) => { | ||
is_playing = false | ||
reject(r) | ||
})*/ | ||
}); | ||
} | ||
// THIS MIGHT BE UNNECESSARY? CUZ SEEKING DOESN'T REQUIRE PLAY | ||
// /** | ||
// * Can try to seek even if the audio context was suspended or closed. Best to use try_seek_async() | ||
// */ | ||
// seek_async(new_time: number) { | ||
// return new Promise((resolve, reject) => { | ||
// this.audio_element.currentTime = new_time | ||
// resolve(null) | ||
// /* audio_element.play().then((s) => resolve(s), (r) => { | ||
// is_playing = false | ||
// reject(r) | ||
// })*/ | ||
// }) | ||
// // } | ||
// /** | ||
// * Unsafe, throws error if failed. Use try_seek_async or seek_async unless you don't care about the result. | ||
// */ | ||
/** | ||
* Unsafe, throws error if failed. Use try_seek_async or seek_async unless you don't care about the result. | ||
*/ | ||
seek(new_time) { | ||
this.audio_element.currentTime = new_time; | ||
//this.audio_element.play().catch((e) => { throw e }) | ||
} | ||
@@ -161,3 +142,3 @@ /** | ||
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") { | ||
this.audio_context.resume().then(undefined, (e) => reject("Context closed or suspended" + e)); | ||
this.audio_context.resume().then(undefined, (e) => reject(new Error("Context closed or suspended" + JSON.stringify(e)))); | ||
} | ||
@@ -170,3 +151,3 @@ if (this.audio_element.paused) { | ||
this.is_playing = false; | ||
reject(r); | ||
reject(new Error("failed to play audio elements" + JSON.stringify(r))); | ||
}); | ||
@@ -195,3 +176,3 @@ } | ||
this.is_playing = false; | ||
reject(r); | ||
reject(new Error(JSON.stringify(r))); | ||
}); | ||
@@ -228,13 +209,23 @@ } | ||
if (this.is_playing) | ||
reject(Error("Already playing")); | ||
resolve(Error("Already playing")); | ||
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") { | ||
this.audio_context.resume().then(undefined, (e) => reject("Context closed or suspended" + e)); | ||
this.audio_context.resume().then(() => { | ||
this.audio_element.play().then((s) => { | ||
this.is_playing = true; | ||
resolve(s); | ||
}, (r) => { | ||
this.is_playing = false; | ||
reject(new Error(JSON.stringify(r))); | ||
}); | ||
}, (e) => reject(new Error("Context closed or suspended" + JSON.stringify(e)))); | ||
} | ||
this.audio_element.play().then((s) => { | ||
this.is_playing = true; | ||
resolve(s); | ||
}, (r) => { | ||
this.is_playing = false; | ||
reject(r); | ||
}); | ||
else { | ||
this.audio_element.play().then((s) => { | ||
this.is_playing = true; | ||
resolve(s); | ||
}, (r) => { | ||
this.is_playing = false; | ||
reject(new Error(JSON.stringify(r))); | ||
}); | ||
} | ||
}); | ||
@@ -248,6 +239,3 @@ } | ||
if (this.is_playing) | ||
resolve(null); | ||
if (this.audio_context.state === "suspended" || this.audio_context.state === "closed") { | ||
this.audio_context.resume(); | ||
} | ||
resolve(Error("Already playing")); | ||
this.audio_element.play().then((s) => { | ||
@@ -258,3 +246,3 @@ this.is_playing = true; | ||
this.is_playing = false; | ||
reject(r); | ||
reject(new Error(JSON.stringify(r))); | ||
}); | ||
@@ -271,3 +259,3 @@ }); | ||
this.is_playing = false; | ||
throw r; | ||
throw new Error(r); | ||
}); | ||
@@ -296,7 +284,7 @@ } | ||
controller.abort(); | ||
reject(e); | ||
reject(new Error("Failed to load new song, error:" + JSON.stringify(e))); | ||
}, { signal: controller.signal }); | ||
this.audio_element.addEventListener("stalled", function stalled_listener(e) { | ||
controller.abort(); | ||
reject(e); | ||
reject(new Error("Failed to load new song, stalled: " + JSON.stringify(e))); | ||
}, { signal: controller.signal }); | ||
@@ -303,0 +291,0 @@ //once aborted, try to set current_song_duration |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46078
613