Giter VIP home page Giter VIP logo

audiooverlap's Introduction

audioOverlap

A simple javascript solution for overlapping Audio objects and playing background music. Useful for HTML5 game development.

Features

  • Easy to use
  • No dependencies needed (pure javascript)
  • Overcomes overlapping limitations of HTML5 with minimal memory load
  • Includes a useful background music player with shuffle feature

Usage

Include:

<script src="path/to/audioOverlap.js"></script>

or

<script src="path/to/audioOverlap.min.js"></script>

Music

Adding background music:

addMusic("song1", "path/to/audioFile.mp3"); //Adds audio file with key: "song1"
addMusic("song2", "path/to/audioFile.mp3"); //Adds audio file with key: "song2"

Setting the first track that plays:

setFirstTrack("song1"); //Sets the first track to play as "song1"

Setting volume for a specific track:

setMusicVolume(0.5, "song1"); //Sets "song1" to 50% volume

Setting volume for all tracks:

setMusicVolume(0.5); //Sets all music tracks to 50% volume

Play the music (only need to call once):

playMusic(); //Initializes the music and starts playing. Only call this once.

Toggle music (play/pause):

toggleMusic(); //Toggles music between playing and paused

Play music:

musicOn(); //Plays music if it is paused, useful if you have seperate play/pause buttons for music

Pause music:

musicOff(); //Pauses music if it is playing, useful if you have seperate play/pause buttons for music

Shuffle music (on by default):

shuffleOn(); //Shuffles music tracks, will not repeat the same song twice in a row

Do not shuffle music:

shuffleOff(); //Does not shuffle music, will play through your music tracks in the order they have been added with addMusic()

Loop music so it keeps playing through all tracks (on by default):

loopMusicOn(); //Loops through your playlist repeatedly

Do not loop music so it only plays one song (do not use unless you fully understand how this code works. Available for specific situations):

loopMusicOff(); //Prevents looping, only plays one song

Sound Effects

Adding sound effects:

addSFX("effect1", "path/to/audioFile.wav", 4); //Adds 4 of "effect1" to the sound effect pool. 4 can be played overlapping.
addSFX("effect2", "path/to/audioFile.wav", 10); //Adds 10 of "effect2" to the sound effect pool. 10 can be played overlapping.

Playing sound effects:

playSFX("effect1"); //Plays "effect1" if it is available in the sound effect pool.

Setting volume for a specific sound effect:

setSFXVolume(0.5, "effect1"); //Sets "effect1" to 50% volume

Setting volume for all sound effects:

setSFXVolume(0.5); //Sets all sound effects to 50% voume

Toggle sound effects (mute/unmute):

toggleSFX(); //Toggles sound effects between mute/unmute

Turn on sound effects (on by default):

SFXOn(); //Turns on sound effects, useful if you have seperate on/off buttons for sound effects

Turn off sound effects:

SFXOff(); //Turns off sound effects, useful if you have seperate on/off buttons for sound effects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.