Skip to content

Commit 05d4b49

Browse files
authored
Merge pull request #26 from Samuelplim/fix/load-audio
add sound imports and error handling to TimerController
2 parents 57f37bf + f5a8cc0 commit 05d4b49

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.parcelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "@parcel/config-default",
3+
"transformers": {
4+
"*.{wav,mp3}": [
5+
"@parcel/transformer-raw"
6+
]
7+
}
8+
}

asset/javascript/TimeController.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import tickTackSoundUrl from '../sound/tick-tack.wav';
2+
import stopSoundUrl from '../sound/stop.mp3';
13
import './helper.js';
24
import { TimerStatus } from './TimerStatus.js';
35
import {
@@ -33,8 +35,15 @@ function TimerController(reference) {
3335
const DEFAULT_INTERVAL = 1000;
3436
const DEFAULT_SECONDS = 30;
3537

36-
const tickTackSound = new Audio('./asset/sound/tick-tack.wav');
37-
const stopSound = new Audio('./asset/sound/stop.mp3');
38+
const tickTackSound = new Audio(tickTackSoundUrl);
39+
const stopSound = new Audio(stopSoundUrl);
40+
tickTackSound.addEventListener('error', e => {
41+
console.error('Erro ao carregar tick-tack.wav:', e);
42+
});
43+
44+
stopSound.addEventListener('error', e => {
45+
console.error('Erro ao carregar stop.mp3:', e);
46+
});
3847

3948
let lastTimerStatus = TimerStatus.STOPPED;
4049
let previousTimerValue = DEFAULT_SECONDS;
@@ -166,7 +175,6 @@ function TimerController(reference) {
166175
if (canStart) {
167176
let seconds = getInputsValueAsSeconds();
168177
seconds--;
169-
170178
if (seconds <= 10) {
171179
lastTimerStatus = TimerStatus.COUNTDOWN;
172180
playCountdownSound();

0 commit comments

Comments
 (0)