Background music for your website
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
examples
src
.gitignore
README.md
gulpfile.js
package-lock.json
package.json

README.md

Ambienx (BackgroundMusic.js)

Use some background music to give your website or webapp some ambience.

var newAmbienx = new Ambienx({
    audioSrc: 'music.mp3',
    audioLoop: false,
    autoPlay: false,
    enabledLoseFocus: true
});

Play

document.querySelector('.play-audio').addEventListener('click', function() {
    newAmbienx.playAudio();
}, false);

Pause

document.querySelector('.pause-audio').addEventListener('click', function() {
    newAmbienx.pauseAudio();
}, false);

Stop

document.querySelector('.stop-audio').addEventListener('click', function() {
    newAmbienx.pauseAudio({stop: true});
}, false);

Fade In

This method accepts an integer argument (1-10), which controls the target fade volume.

document.querySelector('.fade-in-audio').addEventListener('click', function() {
    newAmbienx.fadeInAudio(1, function() {
        <!-- execute callback code here -->
    });
}, false);

Fade Out

This method accepts an integer argument (1-10), which controls the target fade volume. If the target fade volume is not 0, then the audio will keep playing.

document.querySelector('.fade-out-audio').addEventListener('click', function() {
    newAmbienx.fadeOutAudio(0, function() {
        <!-- execute callback code here -->
    });
}, false);

Toggle Fade

This method accepts an argument that is an object, which controls the fade in and fade out volume.

document.querySelector('.toggle-fade-audio').addEventListener('click', function() {
    newAmbienx.toggleFadeAudio({
        fadeInVolume: 1,
        fadeOutVolume: 0
    });
}, false);