class portfolioAudio { fadeIn = 0.01; fadeOut = -0.002; fade = 0.0; stoped = true; ended = true; src = "audio_silence.mp3"; volume = 0.25; currentVolume = 1.0; constructor(url) { this.audio = document.createElement("AUDIO"); this.audio.src = window.urlBase + this.src; this.audio.onended = () => { this.stoped = true; this.ended = true; } document.body.appendChild(this.audio); this.src = url; } eventRefresh() { if (this.fade === 0.0) return; this.currentVolume += this.fade; if (this.currentVolume < 0.0) { this.currentVolume = 0.0; this.audio.volume = 0.0; this.audio.pause(); this.fade = 0.0; this.stoped = true; return; } if (this.currentVolume > 1.0) { this.currentVolume = 1.0; this.audio.volume = this.volume; this.fade = 0.0; return; } this.audio.volume = this.currentVolume * this.volume; } play() { if (this.fade !== 0.0) { this.fade = this.fadeIn; return; } this.stoped = false; if(!this.ended){ this.fade = this.fadeIn; this.audio.play(); return; } this.ended = false; this.audio.src = window.urlBase + this.src; this.audio.load(); this.audio.currentTime = 0.0; this.audio.volume = this.volume; this.audio.play(); } stop() { this.fade = this.fadeOut; } unblock() { this.audio.load(); this.audio.play(); this.audio.pause(); } }