Skip to content

Instantly share code, notes, and snippets.

@nakasyou
Created December 26, 2022 07:37
Show Gist options
  • Save nakasyou/b74374145a6b8120efd83d4c5676fd10 to your computer and use it in GitHub Desktop.
Save nakasyou/b74374145a6b8120efd83d4c5676fd10 to your computer and use it in GitHub Desktop.
JSのサウンド操作
class Sounder{
constructor(url){
this.url=url;
}
make(){
return new (class{
constructor(url){
this.elem=document.createElement("audio");
this.elem.src=url;
}
play(){
this.elem.play();
}
pause(){
this.elem.pause();
}
get time(){
return this.elem.currentTime;
}
set time(time){
this.elem.currentTime=time;
}
get max(){
return this.elem.max;
}
set max(max){
this.elem.max=max;
}
get volume(){
return this.elem.volume;
}
set volume(volume){
this.elem.volume=volume;
}
get ended(){
return this.elem.ended;
}
get speed(){
return this.elem.playbackRate;
}
set speed(speed){
this.elem.playbackRate=speed;
}
})(this.url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment