-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom sounds, frontend sounds, docs for audio
- Loading branch information
Showing
9 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Audio | ||
|
||
Play audio from frontend or using custom `.ogg` sound files. | ||
|
||
!!! | ||
If you want to use custom sound files, put them in the `webview/public/sounds` folder. | ||
!!! | ||
|
||
```ts | ||
import { useAudio } from '@Server/player/audio.js'; | ||
|
||
// Create audio instance for player | ||
const audio = useAudio(player); | ||
|
||
// Play a custom sound from the public folder | ||
audio.playSound('sounds/positive.ogg'); | ||
|
||
// Play a frontend sound that is native to GTA:V | ||
audio.playFrontendSound('TIMER_STOP', 'HUD_MINI_GAME_SOUNDSET'); | ||
``` | ||
|
||
[Frontend Sound List](https://altv.stuyk.com/docs/articles/tables/frontend-sounds.html) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as alt from 'alt-server'; | ||
import { useNative } from './native.js'; | ||
import { Events } from '../../shared/events/index.js'; | ||
import { useWebview } from './webview.js'; | ||
|
||
export function useAudio(player: alt.Player) { | ||
const native = useNative(player); | ||
const webview = useWebview(player); | ||
|
||
function playFrontendSound(audioName: string, audioRef: string) { | ||
native.invoke('playSoundFrontend', -1, audioName, audioRef, true); | ||
} | ||
|
||
function playSound(soundPath: string) { | ||
webview.emit(Events.player.audio.play.local, soundPath); | ||
} | ||
|
||
return { | ||
playFrontendSound, | ||
playSound, | ||
}; | ||
} |
10 changes: 7 additions & 3 deletions
10
src/main/server/webview/index.ts → src/main/server/player/webview.ts
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Events } from '../../src/main/shared/events'; | ||
import { useEvents } from './useEvents'; | ||
|
||
const events = useEvents(); | ||
|
||
let isInitialized = false; | ||
|
||
export function useAudio() { | ||
if (!isInitialized) { | ||
isInitialized = true; | ||
events.on(Events.player.audio.play.local, play); | ||
} | ||
|
||
async function play(path: string) { | ||
const audio = new Audio(path); | ||
audio.loop = false; | ||
await audio.play(); | ||
|
||
// this._audio[soundID] = new Audio(path); | ||
// this._audio[soundID].soundID = soundID; | ||
// this._audio[soundID].addEventListener('ended', this.audioStopped); | ||
// this._audio[soundID].crossOrigin = 'anonymous'; | ||
// const ambientContext = new AudioContext(); | ||
// const source = ambientContext.createMediaElementSource(this._audio[soundID]); | ||
// this._ambientPan[soundID] = ambientContext.createStereoPanner(); | ||
// source.connect(this._ambientPan[soundID]); | ||
// this._ambientPan[soundID].connect(ambientContext.destination); | ||
// this._audio[soundID].setAttribute('src', path); | ||
// this._ambientPan[soundID].pan.value = pan; | ||
} | ||
|
||
return { | ||
play, | ||
}; | ||
} |
Empty file.
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