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

ember-cli-bg-music

v0.0.13

Published

The default blueprint for ember-cli addons.

Downloads

2

Readme

Ember-cli-bg-music

This README outlines the details of collaborating on this Ember addon.

Installation

  • git clone this repository
  • npm install
  • bower install

Running

  • ember server
  • Visit your app at http://localhost:4200.

Running Tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://ember-cli.com/.


How To Use The Addon

Initial Setup

In your Ember app's root directory run

npm install ember-cli-bg-music --save

Before the bg-music addon can work, you must first provide a path to the audio file for the addon to consume. To do this, navigate to the config folder and open the environment.js file. Inside the file you must define a musicURL property on the ENV object otherwise Ember will throw an error and your application won't load. The musicURL property takes as its value the path to the audio file. If you placed your audio file in the public directory, you can simply pass in the filename of the audio file as the value for the musicURL property.

For example:

config/environment.js
musicURL: "jazz.mp3"

Or if you placed your audio file in a subdirectory nth-level deep:

config/environment.js
musicURL: "assets/jazz.mp3"

or

config/environment.js
musicURL: "assets/audio/jazz.mp3"

Play Your Background Music

The background music doesn't play on page load by default because in many cases it can be jarring when the page hasn't finished the initial load or if you want to first perform a preloader animation.

But if you do want your background music to play on page initialization, then in your config/environment.js file, you must define the playOnInit property and set it to true.

config/environment.js
playOnInit: true

Now your background music should play on page initialization.

Service

Note that Bg-music and all its properties and methods are defined on an Ember service object. To access the service, you must first define or "inject" the service into a controller or component. Because you want your background music to be available everywhere on your page, it'd be a good idea to just inject the Bg-music service into the application controller (which lives on the top-level of an Ember app and can pass data and actions anywhere down your page).

For example, if your page doesn't already have an application controller file generated, then go ahead and generate it:

ember generate controller application

This should create an application.js file in your app/controllers folder. Open the file and inject the Bg-music service:

app/controllers/application.js
bgMusic: Ember.inject.service()

Now you should have full access to Bg-music's methods and properties!

Methods

Bg-music provides eight methods out of the box:

toggleMusic(turnOffManualStop)

Toggles the background music on and off.

playMusic(turnOffManualStop)

Plays or resumes the background music.

e.g.

this.get('bgMusic').play()

Note that bgMusic is the property name of the Ember injected service

stopMusic(turnOnManualStop)

Stops the background music completely.

Bg-music automatically turns off the background music when the page is out of focus (like when the user tabs or navigates away from the page) and then turns the background music back on when the page is back in focus. Passing in true will make sure that if the user had explicitly turned off the background music, the background music will stay turned off when the page is back in focus.

For example let's say you define an action method called stopMusic() that is called whenever the user clicks an element to turn off the background music. If you want the background music to stay turned off when the page is out of focus and later back in focus, then you'd want to use stop() and pass in true.

stopMusic(true);

Be aware that if you pass in true for stop(), you should remember to pass in true for play() as well to let the addon know that the background music will play when the page is back in focus.

stopMusic(true);
playMusic(true);

Sets the isManualStop property to false. You want to do this if the user has explicitly turned the background music back on.

mute(turnOnManualStop)

Mutes the background music but does not stop it.

unmute(turnOffManualStop)

Unmutes the background music.

fadeout()

Gradually mutes the background music but does not stop it.

fadein()

Gradually unmutes the background music.