Forum Discussion

Ann-Katharin105's avatar
Ann-Katharin105
Community Member
4 days ago
Solved

Audio-Button functions and states within selfbuild WBT menue and options

Hi everyone,  currently I am working on a selfbuild WBT menue with own options on buttons (like refresh, fullscreen, turn on/off subtitles, etc.). This also includes a button for un/muting audio. (...
  • Nedim's avatar
    Nedim
    2 days ago

    Ann-Katharin105​  Make sure the volBtn object ID across all scripts matches the volBtn object ID in your current project. You may also want to use this script when the timeline starts to reference the object ID only once, and then execute JavaScript to call the toggleVolume() function when the volBtn  and Hotspot Audio are clicked.

    Execute JavaScript when the timeline starts on this slide:

    window.syncVolumeUI = function() {
        const volBtn = object('6K0zFZzoRzO'); // replace with current ID
        const currentVol = DS.appState.currentVolume();
        
        setVar("volumeOn", currentVol > 0);
        volBtn.state = (currentVol > 0) ? "Normal" : "_default_Selected";
    };
    
    window.toggleVolume = function() {
        const currentVol = DS.appState.currentVolume();
        const newVol = currentVol > 0 ? 0 : (DS.appState.lastVolume || 1);
        
        DS.appState.setVolume(newVol);
        window.syncVolumeUI(); // Update UI after toggling
    };
    
    syncVolumeUI();

    Execute JavaScript when the use clicks volBtn and Hotspot Audio:

    toggleVolume()

    This is a simplified approach to avoid the risk of forgetting to add the object ID in multiple scripts.