Skip to content

Commit

Permalink
chore: reviews changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JaimeTorrealba committed Oct 5, 2023
1 parent 3d790bc commit 535801d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions docs/guide/abstractions/global-audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import { GlobalAudio } from '@tresjs/cientos'

## Props

| Prop | Description | Default |
| :------------- | :------------------------------------------------- | --------------------- |
| `src` | Path to your audio file | |
| `playElement` | Id of the DOM element that trigger the play state | `renderer.domElement` |
| `pauseElement` | Id of the DOM element that trigger the pause state | |
| `stopElement` | Id of the DOM element that trigger the stop state | |
| `loop` | If the audio must be replayed when ends | `false` |
| `volume` | Volume of the audio. | `0.5` |
| `playbackRate` | PlaybackRate of the audio | `1` |
| Prop | Description | Default |
| :------------- | :-------------------------------------------------- | --------------------- |
| `src` | Path to your audio file | |
| `playElement` | Id of the DOM element that triggers the play state | `renderer.domElement` |
| `pauseElement` | Id of the DOM element that triggers the pause state | |
| `stopElement` | Id of the DOM element that triggers the stop state | |
| `loop` | If the audio must be replayed when ends | `false` |
| `volume` | Volume of the audio | `0.5` |
| `playbackRate` | PlaybackRate of the audio | `1` |

## Events

| Event | Description |
| :---------- | :---------------------------------------------------------------- |
| `isPlaying` | Dispatched when the Audio change its state (play, pause or stop). |
| `isPlaying` | Dispatched when the Audio change its state (play, pause or stop) |
4 changes: 2 additions & 2 deletions playground/src/pages/abstractions/GlobalAudioDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const options = useControls({
/>
<GlobalAudio
:src="exampleAudio"
:volume="options.volume.value.volume"
:volume="0.5"
:loop="false"
:playback-rate="options.playbackRate.value.playbackRate"
:playback-rate="1"
play-element="playBtn"
pause-element="pauseBtn"
stop-element="stopBtn"
Expand Down
12 changes: 6 additions & 6 deletions src/core/abstractions/GlobalAudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,31 @@ export const GlobalAudio = defineComponent<AudioProps>({
}
})

watch(() => [props.playbackRate], () => sound.setPlaybackRate( props.playbackRate || 1 ), { immediate: true })
watch(() => [props.volume], () => sound.setVolume( props.volume || 0.5 ), { immediate: true })
watch(() => [props.loop], () => sound.setLoop( props.loop || false ), { immediate: true })
watch(() => [props.playbackRate], () => sound.setPlaybackRate( props.playbackRate ?? 1 ), { immediate: true })
watch(() => [props.volume], () => sound.setVolume( props.volume ?? 0.5 ), { immediate: true })
watch(() => [props.loop], () => sound.setLoop( props.loop ?? false ), { immediate: true })
watch(() => [props.src], async () => {
const buffer = await audioLoader.loadAsync( props.src)
sound.setBuffer( buffer )

}, { immediate: true })

const selector = document.getElementById(props.playElement || '')
const selector = document.getElementById(props.playElement ?? '')
const btnPlay = selector ? selector : renderer.value.domElement
useEventListener(btnPlay, 'click', () => {
sound.play()
emit('isPlaying', sound.isPlaying)
})

const btnPause = document.getElementById(props.pauseElement || '')
const btnPause = document.getElementById(props.pauseElement ?? '')
if (btnPause) {
useEventListener(btnPause, 'click', () => {
sound.pause()
emit('isPlaying', sound.isPlaying)
})
}

const btnStop = document.getElementById(props.stopElement || '')
const btnStop = document.getElementById(props.stopElement ?? '')
if (btnStop) {
useEventListener(btnStop, 'click', () => {
sound.stop()
Expand Down

0 comments on commit 535801d

Please sign in to comment.