npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backbone.soundmanager2

v0.1.2

Published

Wrapper to use SoundManager2 audio player with backbone models.

Downloads

2

Readme

backbone.soundmanager2

Backbone.SoundManager2 is a wrapper around SoundManager2 that helps including and using it within a Backbone application.

How to use?

You should initialize a single Backbone.SoundManager2 player object, for instance as a global App.player:

App.player = new Backbone.SoundManager2

The player expects to be given playable objects, that is Backbone.Model objects, extended with a getAudioURL asynchronous method to return a URL to be played.

App.player.load playable    # Play a playable model
App.player.toggle()         # Toggle play/pause
App.player.stop()           # You got this one, right? :-)
App.player.setPosition 0.25 # Set playing position to 25%
App.player.setVolume   0.75 # Set volume to 75%

Please, refer to the code for more details about the available functions. Each of them are properly documented.

How to integrate?

A Backbone.SoundManager2 instance will emit events related to its actions. Those events are also emitted on any playable model current being played.

You can use those to integrate the player within you Backbone.View. For instance, for a global player view:

class App.View.Player extends Backbone.View
  initialize: ->
    App.player.on "released", @clear
    App.player.on "loaded",   @loaded
    App.player.on "loading",  @loading
    App.player.on "paused",   @paused
    App.player.on "played",   @played
    App.player.on "playing",  @updatePosition
    App.player.on "resumed",  @played
    App.player.on "stopped",  @stopped
    App.player.on "finished", @finished

  updatePosition: (sound) =>
    return unless sound?

    @$(".bar .filler").css "width",
      "#{Math.round(100 * sound.position / sound.durationEstimate)}%"

    position = new Date sound.position

    # Duration is an estimate so we're better
    # computing it each time..

    duration = new Date sound.durationEstimate

    @$(".played").text _.sprintf("%d:%02d", position.getMinutes(), position.getSeconds())
    @$(".remaining").text _.sprintf("%d:%02d", duration.getMinutes(), duration.getSeconds())

Likewise, for a view referring to a playable model:

class App.View.Track extends Backbone.View
  initialize: ->
    @model.on "player:paused",   @paused
    @model.on "player:played",   @played
    @model.on "player:resumed",  @played
    @model.on "player:stopped",  @stopped
    @model.on "player:finished", @finished

backbone.modelizer

If backbone.modelizer is installed, playable.retain() will be called when playable is being played and playable.release() will be called when playable is being released.

Using

Just include backbone.soundmanager2.js after including backbone.js and soundManager2 and before any code that makes use of it and you're ready to go!

If you want to use it as a browserify module, simply include it in your package.json

"dependencies": {
  "backbone.soundmanager2": "git://github.com/audiosocket/backbone.soundmanager2.git"
}

Then, after doing npm install, you'll be able to require it in your app. For example:

var Backbone.SoundManager2 = require('backbone.soundmanager2');