A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.

Related tags

Video/Audio SoundJS
Overview

SoundJS

SoundJS is a library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers, including using a target plugin model to provide an easy way to provide additional audio plugins like a Flash fallback (included, but must be used separately from the combined/minified version).

A mechanism has been provided for easily tying in audio preloading to PreloadJS.

Example

createjs.Sound.on("fileload", handleLoadComplete);
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.registerSound({src:"path/to/sound.ogg", id:"sound"});
function handleLoadComplete(event) {
	createjs.Sound.play("sound");
}

License

Built by gskinner.com, and released for free under the MIT license, which means you can use it for almost any purpose (including commercial projects). We appreciate credit where possible, but it is not a requirement.

Support and Resources

Classes

Sound

The core API for playing sounds. Call createjs.Sound.play(sound, ...options), and a sound instance is created that can be used to control the audio, and dispatches events when it is complete, loops, or is interrupted.

SoundInstance

A controllable sound object that wraps the actual plugin implementation, providing a consistent API for audio playback, no matter what happens in the background. Sound instances can be paused, muted, and stopped; and the volume, pan (where available), and position changed using the simple API.

WebAudioPlugin

The default, built-in plugin, which uses Web Audio APIs to playback sounds. Note that WebAudio will fail to load when run locally, and the HTML audio plugin will be used instead.

HTMLAudioPlugin

The fallback built-in plugin, which manages audio playback via the HTML5 tag. This will be used in instances where the WebAudio plugin is not available.

CordovaAudioPlugin

An additional plugin which will playback audio in a Cordova app and tools that utilize Cordova such as PhoneGap or Ionic. You must manually register this plugin. Currently available on github since SoundJS-0.6.1.

FlashAudioPlugin

An additional plugin which uses a flash shim (and SWFObject) to playback audio using Flash. You must manually set up and register this plugin.

Documentation and examples

Have a look at the included examples and API documentation for more in-depth information.

Comments
  • WebAudioPlugin not registering correctly when running Chrome from local file

    WebAudioPlugin not registering correctly when running Chrome from local file

    Running the TestSuite.html test-app from the website works fine. It registers, detects and uses the WebAudioPlugin correctly.

    Running the same TestSuit.html test-app from local harddisk (downloaded from github trunk) doesn't work and it reverts to the HTMLAudioPlugin (forcing the code to register only WebAudioPlugin doesn't work, resulting in a message that Chrome doesn't support SoundJs).

    What gives?

    opened by bbottema 19
  • Registering a sound twice breaks the sound

    Registering a sound twice breaks the sound

    If you reregister a sound after it has successfully played before any subsequent attempts to play the sound fail (this is because isPreloadComplete forever returns false).

    This is exacerbated by the lack of a clean way of telling whether an id has already been registered (getSrcById returns the id itself if no url is found, the purpose of which I'm not sure).

    A use case for this; A game is re-entered (without page reload) which then registers it's sound library without realising that these sounds are already registered.

    I am not sure if this issue also occurs if the second registration URLs are different from the first (i.e. changing the sound registered to an id).

    opened by TomByrne 14
  • Android Webview issues?

    Android Webview issues?

    Hi. I'm trying to use soundJS in an Android Webview. The problem is that when calling play(), the state goes to playFailed and the AJAX request is marked as Cancelled Is this known issue?

    opened by tehmaestro 11
  • Allowing src with no extension

    Allowing src with no extension

    Hey, I have a small question. Is there anyway I can modify the library so it allows me to set the SRC without an extension, like .mp3 ? I would like to have something like http:/www.test.com/audio/1233445 . This link will be parsed by a PHP script, which will return a Content-Type: audio/mpeg.

    Anyway I can do this? Thank you so much.

    PS: I get this: Uncaught TypeError: Cannot read property 'apply' of undefined Just after I do this: window.createjs.Sound.registerSound(audio.src, audio.id, audio.data);

    question 
    opened by tehmaestro 11
  • no support for iOS?

    no support for iOS?

    Hi, how about supporting iOS? I read the code and found SoundJS doesn't support iOS by browser detection. But, I found another library that supports iOS. http://www.schillmania.com/projects/soundmanager2/

    SoundJS + PreloadJS is awesome. But it's better if it supports iOS, I think.

    opened by Takazudo 11
  • Sound balance issue with latest version of Chrome

    Sound balance issue with latest version of Chrome

    Since updating to Google Chrome 44.0.2403.89, all sounds only play in the right channel. This happens on the homepage demo: http://www.createjs.com/soundjs

    opened by glecollinet 10
  • DELIMITER = deprecated?

    DELIMITER = deprecated?

    I see that the file path has been deprecated. Would it be possible to leave it in? Currently I store all my mp3 in one folder, wav's in another folder and ogg's in another folder.

    With the new 'alternateExtensions' I won't be able to do this and will have to mix/put all the files in one folder.

    The alternative is I would have to detect which file type is the one that can be played and then do my own regex on the file path that is then passed into the manifest.

    It's no big deal :)

    enhancement 
    opened by aholla 10
  • Preload and Play sound in IE8 not working

    Preload and Play sound in IE8 not working

    I tried to preload and play an audio in IE8 but it's not working. I did my test with the version NEXT of your PreloadJs and SoundJs (of the version 4.1) using Flash plugin and this is were it crashes.

    I then tried running your example that was on your website (SoundJS-release_v0.4.1/examples/PreloadAndPlay.html) and i'm getting this error:

    Sorry! SoundJS is not currently supported in your browser. Please log a bug with the device and browser you are using. Thank you.

    Do you support IE8?

    If so, what would be the steps to follow to get it to work

    opened by ghost 10
  • Cordova on android music does not play.

    Cordova on android music does not play.

    We have HTML5 game which is using soundjs for handling sounds in game.

    Currently we have problem with android. Previously we have had problem with sounds in our app and we solved it using cordova media plugin. Basically it calls android native player to play sounds.

    Could you please advise should we continue using SoundJS or currently it is not possible.

    Thanks

    enhancement question 
    opened by denza 9
  • soundjs not supported on IE11 (WP8.1)

    soundjs not supported on IE11 (WP8.1)

    After I use WP8.1(ie11) to test soundjs,it shows not support my device. Please help me to double check it, many thanks.

    Here is the site: http://www.createjs.com/#!/SoundJS/demos/testSuite

    bug 
    opened by KiritoStudio 9
  • getDuration() of Flash SoundInstance is always 0

    getDuration() of Flash SoundInstance is always 0

    I am using the mobile-safe workflow and create sounds like this (after having them loaded through a Manifest):

    var scope = this;
    
    // Play the sound and add a complete listener
    this.soundInstance = createjs.Sound.play(id, {offset: this.playOpts.offset});
    this.soundInstance.addEventListener('complete', function (e) {
        scope.soundCompleteHandler(null);
    });
    
    // Find out the duration
    this.soundInstanceDuration = this.soundInstance.getDuration(); // logs '0' for Flash
    

    This works fine for any plugin, except for Flash. I tested that by registering only Flash while in the init() function. I tried using the success event, as the docs state that a sound needs to be playing in order for the duration to be accurate, but without any luck (this might be pseudo code as I have already deleted it in my editor):

    var scope = this, ref;
    
    // Add listeners and play the sound
    ref = this.soundInstance = createjs.Sound.createInstance(id, this.playOpts.offset, null);
    this.soundInstance.addEventListener('success', function (e) {
        scope.soundInstanceDuration = e.target.getDuration(); // logs '0' for Flash
    });
    this.soundInstance.addEventListener('complete', function (e) {
        scope.soundCompleteHandler(null);
    });
    
    // Find out the duration
    this.soundInstanceDuration = this.soundInstance.getDuration(); // logs '0' for Flash
    

    I have a progress bar hooked up to an interval script, but without the duration it just doesn't work at all. I'd love to find a fix for this issue!

    Thanks in advance :)

    bug 
    opened by flovan 9
  • soundjs play mp3, When playing at a higher speed, the pitch becomes higher

    soundjs play mp3, When playing at a higher speed, the pitch becomes higher

    The soundjs plugin is used in the project. When the mp3 is played in fast forward, the pitch becomes higher。

    Is it possible to not raise the pitch?

    demo:

    https://codesandbox.io/s/fervent-grass-g9j248?file=/index.html

    opened by wdydxf 0
  • Still maintained?

    Still maintained?

    I'm diving into new project which will require a module to work with audio such as SoundJS, however, it seem like there is very little maintenance and bug fixes going on. Is this package still maintained?

    opened by Yahav 1
  • Sound randomly stopping after minimizing/maximizing iPadOS 14.4.2

    Sound randomly stopping after minimizing/maximizing iPadOS 14.4.2

    We found that the music background of one of our projects was not being restored after minimizing and maximizing the game in mobile Safari with iPadOS 14.4.2 on an iPad Air 3rd Gen. This is a random bug and sometimes the music pauses/resumes correctly but if you repeat this process many times you can hear the sound not being restored eventually.

    https://drive.google.com/drive/u/0/folders/1t3PBpqPUjzfNRIXDMxfiu5gDK5UFFsD0

    Is this a known issue? We are attaching a video of the issue. This can be reproduced with the standard demos.

    opened by ex 1
  • Safari Never Auto-Play setting causes long delay ending in `fileerror` with no information.

    Safari Never Auto-Play setting causes long delay ending in `fileerror` with no information.

    Issue Details

    • Version used: 1.0.0

    • Describe whats happening: If desktop Safari is set to Never Auto-Play, after registering a sound, there is a several second delay, and then a fileerror event. The event doesn't contain any info to determine that this setting was the cause.

    Example

    <!DOCTYPE html>
    
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <title>Sound JS Test</title>
        <script src="https://code.createjs.com/1.0.0/soundjs.min.js"></script>
      </head>
    
      <body onload="setup()">
        <script>
          function setup() {
            console.log("setup");
            createjs.Sound.registerPlugins([createjs.HTMLAudioPlugin]);
          }
    
          function playSound() {
            console.log("playSound");
            
            createjs.Sound.on("fileload", function (result) {
              console.log("fileload", result);
              createjs.Sound.play("tone");
            });
            
            createjs.Sound.on("fileerror", function (error) {
              console.log("fileerror", error);
            });
            
            createjs.Sound.registerSound("audio/tone.mp3", "tone");
          }
        </script>
    
        <button onclick="playSound()">Play Sound</button>
      </body>
    </html>
    

    Resulting logs:

    [Log] setup (sound-js, line 13)
    [Log] playSound (sound-js, line 18)
    [Log] fileerror (sound-js, line 24)
    
    Event
      bubbles: false
      cancelable: false
      currentTarget: function()
      data: 100
      defaultPrevented: false
      eventPhase: 2
      id: "tone"
      immediatePropagationStopped: false
      propagationStopped: false
      removed: false
      sprite: undefined
      src: "audio/tone.mp3" 
      target: function()
      timeStamp: 1613432337722 
      type: "fileerror"
      Event Prototype
    
    • OS & Browser version Safari Version 14.0.3 (16610.4.3.1.4)

    • Do you know of any workarounds? Interestingly, if createjs.Sound.play("tone"); is called within the fileerror callback, the sounds still plays?! However, this is a ridiculous hack which breaks any other attempts at actually handling errors.

    How can I react and or work around the Never Auto-Play setting in desktop Safari?

    verified 
    opened by curiousdustin 20
  • no possiblity to pauze music with the new button in chrome 'to change the music from tab to tab'

    no possiblity to pauze music with the new button in chrome 'to change the music from tab to tab'

    I can not find the music setting of zimjs into the chrome list of sounds.. more info about this new thing (januari 2020) https://blog.google/products/chrome/manage-audio-and-video-in-chrome

    can this be checked? I tried it with the example of http://zimjs.com/elearning/quiz.html and there comes no website with the music in it..

    Thanks to fix this Karel

    opened by karelrosseel 0
Releases(1.0.0)
Owner
CreateJS
A suite of open source libraries and tools for building rich interactive content on open web technologies.
CreateJS
HTML5

One file. Any browser. Same UI. Author: John Dyer http://j.hn/ Website: http://mediaelementjs.com/ License: MIT Meaning: Use everywhere, keep copyrigh

MediaElement.js 8k Jan 8, 2023
An open source Javascript framework for detecting the Adobe Flash Player plugin and embedding Flash (swf) files.

— IMPORTANT UPDATE —¶ ↑ SWFObject is no longer in active development. Flash Player is on the decline, and the authors of SWFObject have moved on to ot

null 1.2k Nov 27, 2022
A JavaScript library for optimizing html pages with video content that prevents videos from loading on mobile devices.

?? js-vido — JavaScript Video Download Optimizer A JavaScript library for optimizing html pages with video content that prevents videos from loading o

Ariel Montes 1 Feb 9, 2021
now-playing: A website to show what I'm currently listening to on Spotify Run on Repl.it

now-playing: A website to show what I'm currently listening to on Spotify ❓ How does it work? This project is split into two parts - the frontend and

Connor Dennison 3 Apr 29, 2022
update your twitter banner with the song you're currently playing on Spotify

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Dunsin 4 Oct 17, 2022
Video.js - open source HTML5 & Flash video player

Video.js - HTML5 Video Player Video.js is a web video player built from the ground up for an HTML5 world. It supports HTML5 video and Media Source Ext

Video.js 34.8k Jan 5, 2023
JavaScript plugin for playing sounds and music in browsers

JavaScript plugin for playing sounds on user actions and page events. Version: 3.0.7 Project page and demos Download ZIP Support the plugin on GitHub

Denis Ineshin 704 Sep 24, 2022
This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library included.

Aim-Player This is a simple web based media player for playing video and audio. Build with pure HTML, CSS and Javascript. No framework or library incl

Aim Mikel 2 Jun 27, 2021
AmplitudeJS: Open Source HTML5 Web Audio Library. Design your web audio player, the way you want. No dependencies required.

Documentation • Examples • Tutorials • Support Us • Get Professional Help AmplitudeJS is a lightweight JavaScript library that allows you to control t

Server Side Up 3.9k Jan 2, 2023
Audio visualizer library for javascript. Create dynamic animations that react to an audio file or audio stream.

Wave.js Audio visualizer library for javascript. Installation Install With CDN <script src="https://cdn.jsdelivr.net/gh/foobar404/wave.js/dist/bundle.

Austin Michaud λ 497 Dec 21, 2022
A simple Multi Guild Modmail Bot coded in v13 using the enmap Database Working on any host, like repl.it or vps! Its fast and working bug free + Security options!

Multiguild-Modmail A simple Multi Guild Modmail Bot coded in v13 using the enmap Database Working on any host, like repl.it or vps! Its fast and worki

Tomato6966 54 Oct 20, 2022
Base Bot WhatsApp With Baileys Multi Device, Working Heroku No Suspend ☑️, Working Okteto No Suspend ☑️

Base Bot WhatsApp Multi Device With Baileys Multi Device Note Base Ini Free Untuk Semua, Tidak Untuk Diperjualbelikan Kecuali Lu Udah Tambahin Fitur L

Nazril Afandi 36 Dec 25, 2022
Buzz, a Javascript HTML5 Audio library

Buzz is a small but powerful Javascript library that allows you to easily take advantage of the new HTML5 audio element. It tries to degrade silently on non-modern browsers.

Jay Salvat 1.2k Dec 10, 2022
Enables

HTML5 video made easy All it takes is a single line of code to make HTML5 video and audio tags work in all major browsers. How to enable video and aud

Dave Hall 1.3k Dec 17, 2022
Secretly record audio and video with chromium based browsers

snoop TCC restricts access to the device camera and microphone to protect user data from unauthorized access. But... If you trusted your browser with

BreakPoint Technologies 10 Aug 30, 2022
Recap let's you recap on your favourite social network videos by downloading them on your devices, from the range of YouTube, SoundCloud, Facebook, Twitter, Instagram, TikTok, Vimeo, Dailymotion, VK, or AOL.

Recap A Social Network Video Downloader Recap let's you recap on your favourite social network videos by downloading them on your devices, from the ra

John Oladele 4 Sep 24, 2022
:musical_score: ts-audio is an agnostic library that makes it easy to work with AudioContext and create audio playlists in the browser

ts-audio · ts-audio is an agnostic and easy-to-use library to work with the AudioContext API and create Playlists. Features Simple API that abstracts

Evandro Leopoldino Gonçalves 284 Dec 25, 2022
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion

ReactPlayer A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia, M

Pete Cook 7.2k Jan 4, 2023
I’m a very useful music bot that can make you play a music with a simple command! I have a lot of good commands that you can have a better experience playing your favorites songs!

I’m a very useful music bot that can make you play a music with a simple command! I have a lot of good commands that you can have a better experience playing your favorites songs!

Hugo Kishi 2 Aug 16, 2022