Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set volume to audio components #580

Open
lobau opened this issue Apr 12, 2024 · 2 comments
Open

Set volume to audio components #580

lobau opened this issue Apr 12, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@lobau
Copy link
Contributor

lobau commented Apr 12, 2024

I'm trying to change the volume of an audio element, but I can't figure out how.

The documentation is limited on audio (should we have a page for it?)
https://docs.mrjs.io/js-api/audiosystem/#audiosystemsetaudiostateentity-state

I tried this, but it didn't work:

// This works
this.sounds.bgMusic.components.set('audio', { state: 'play' })

// This doesn't work, but I wish it did :D
this.sounds.bgMusic.components.set('audio', { state: 'play', volume: 0.3 });
@github-project-automation github-project-automation bot moved this to To-Triage in MRjs && Docs Apr 12, 2024
@lobau lobau moved this from To-Triage to Todo in MRjs && Docs Apr 12, 2024
@lobau lobau added the enhancement New feature or request label Apr 12, 2024
@lobau lobau moved this from Todo to To-Triage in MRjs && Docs Apr 12, 2024
@hanbollar
Copy link
Contributor

hanbollar commented Apr 12, 2024

we just dont handle that atm, that's something definitely we can add :D

adding note below for the threejs setup for it - would just need to add an adjustment to the AudioSystem to incorporate that:

// To increase the volume
function increaseVolume() {
    if (audio.getVolume() < 1.0) {
        audio.setVolume(audio.getVolume() + 0.1); // Increase volume by 0.1
    }
}

// To decrease the volume
function decreaseVolume() {
    if (audio.getVolume() > 0.0) {
        audio.setVolume(audio.getVolume() - 0.1); // Decrease volume by 0.1
    }
}

where audio is something previously setup like:

// Assuming audio is your THREE.Audio object
let audio = new THREE.Audio(listener);

// Set the audio source
let audioLoader = new THREE.AudioLoader();
audioLoader.load('path/to/audio.mp3', function(buffer) {
    audio.setBuffer(buffer);
    audio.setLoop(true);
    audio.setVolume(0.5); // Set initial volume here
    audio.play();
});

@hanbollar
Copy link
Contributor

something to figure out - want to set 'volume' attribute

PositionalAudio extends directly from Audio so it should have access to volume internally directly

want to be able to do something like:

this.sounds.bgMusic.components.set('audio', { state: 'play', volume: 0.3 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: To-Triage
Development

No branches or pull requests

2 participants