Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mediaStatus = {
- playing: 'playing',
- paused: 'paused',
- ended: 'ended'
- }
- const congratsSound = {
- file: 'Niveles.mp3',
- media: null,
- started: null,
- playFor: 0,
- status: mediaStatus.paused,
- create() {
- this.media = createAudio(this.file);
- },
- play(seconds) {
- this.media.play();
- this.status = mediaStatus.playing;
- this.started = millis();
- this.playFor += seconds * 1000;
- },
- reset() {
- this.media.stop();
- this.status = mediaStatus.paused;
- this.started = null;
- },
- update() {
- if (this.status === mediaStatus.paused || this.started === null) {
- return;
- }
- const duration = this.media.duration() * 1000;
- if (millis() >= this.started + duration) {
- this.status = mediaStatus.ended;
- this.started = null;
- return;
- }
- if (millis() >= this.started + this.playFor) {
- this.media.stop();
- this.status = mediaStatus.paused;
- this.started = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement