Created
December 26, 2022 07:37
-
-
Save nakasyou/b74374145a6b8120efd83d4c5676fd10 to your computer and use it in GitHub Desktop.
JSのサウンド操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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