import {NssAudio} from"nui://nss_libs/ui/NssAudio/NssAudio.js";/** * @type{NssAudio} */constaudio_player=newNssAudio('nui://RESOURCE_NAME/PATH/TO/YOUR/SOUNDS/');audio_player.setVolume(0.5);audio_player.playAudio('YOUR_SOUND_FILE.mp3'); // Returns promise which is resolved if sound was ended
Integrated SFX commands
import {NssAudio} from"nui://nss_libs/ui/NssAudio/NssAudio.js";// Availabe commands:NssAudio.playSfxBack();NssAudio.playSfxNext();NssAudio.playSfxUpDown();NssAudio.playSfxShowMenu();NssAudio.playSfxIndexOpen();NssAudio.playSfxIndexClose();NssAudio.playSfxIndexClose();NssAudio.playSfxHideMenu1();NssAudio.playSfxHideMenu2();NssAudio.playSfxHideMenu3();// Custom volume exampleNssAudio.playSfxBack(1); // 100% volumeNssAudio.playSfxBack(0.5); // 50% volumeNssAudio.playSfxBack(0.25); // 25% volume// Other commandsconstinstance=newNssAudio('nui://RESOURCE_NAME/PATH/TO/YOUR/SOUNDS/');instance.playAudio(filename, prevent_reset, loop);instance.loopAudio(filename);instance.setVolume(volume);instance.stop(force_ended_event); // fire_ended_event is optional, default is false, but fires ended event if sound file was ended
instance.isPlaying();instance.getDurationInPercent(); // Returns false if duration is not availableinstance.getCurrentTime();instance.getDuration(); // Returns false if duration is not availableinstance.setRandomPlaybackRate(min, max); // Set random playback rate between min and max. Automated pitching.