Skip to content

rivea0/ambient-sounds-web-components

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ambient Sounds Web Components

Example <coffee-shop-ambience> component:

Coffee shop ambience small demo

See full demo.

Components

Fire

<fire-ambience>
</fire-ambience>

Thunderstorm

<thunderstorm-ambience>
</thunderstorm-ambience>

Heavy rain

<heavy-rain-ambience>
</heavy-rain-ambience>

Rain on window

<rain-on-window>
</rain-on-window>

Waves

<waves-ambience>
</waves-ambience>

Wind

<wind-ambience>
</wind-ambience>

Coffee shop

<coffee-shop-ambience>
</coffee-shop-ambience>

Birds

<birds-ambience>
</birds-ambience>

Cat purr

<cat-purr>
</cat-purr>

Books

<books-ambience>
</books-ambience>

Walking on forest road

<walking-on-forest-road>
</walking-on-forest-road>

Typing

<typing-ambience>
</typing-ambience>

Crickets at night

<crickets-at-night>
</crickets-at-night>

Eerie forest

<eerie-forest-ambience>
</eerie-forest-ambience>

Usage

The components import and extend the PlayBox class, so make sure you have play-box.js.

Add the component you'd like to use, for example:

<script type="module" src="heavy-rain.js" defer></script>

Make sure you have the assets (audio and image sources) for the components. (for example, assets/heavy-rain).

Then use it in your HTML:

<heavy-rain-ambience></heavy-rain-ambience>

Attributes

The PlayBox element has the following attributes:

  • overlayColor
    • Border and button background color.
    • Default: #000.
  • iconColor
    • Play/pause SVGs' stroke color.
    • Default: #fff.
  • buttonPosition
    • One of "top", "top-left", "top-right", "center", "bottom", "bottom-left", "bottom-right".
    • Default: "center".
  • boxBorderRadius
    • One of "none", "full", "x-small", "small", "medium", "large", "x-large".
    • Default: "full".
  • buttonBorderRadius
    • One of "none", "full", "x-small", "small", "medium", "large", "x-large".
    • Default: "full".

Make your own

You can create your own custom element by extending the PlayBox class.

Define the path or URL to audio and image sources:

const AUDIO_SRC = '/path/to/audio/file';
const IMAGE_SRC = '/path/to/image/file';

Create your custom element class, and set the audio and image:

class MyCustomElement extends PlayBox {
  constructor() {
    super();
  }

  connectedCallback() {
    super.connectedCallback();

    this._audioEl.src = AUDIO_SRC;
    this._boxDiv.style.backgroundImage = `url("${IMAGE_SRC}")`;
  }
}

Register it:

if (!customElements.get('my-custom-element')) {
  customElements.define('my-custom-element', MyCustomElement);
}

Here it is in full:

const AUDIO_SRC = '/path/to/audio/file';
const IMAGE_SRC = '/path/to/image/file';

class MyCustomElement extends PlayBox {
  constructor() {
    super();
  }

  connectedCallback() {
    super.connectedCallback();

    this._audioEl.src = AUDIO_SRC;
    this._boxDiv.style.backgroundImage = `url("${IMAGE_SRC}")`;
  }
}

if (!customElements.get('my-custom-element')) {
  customElements.define('my-custom-element', MyCustomElement);
}

Credits

License

MIT

About

Custom audio player elements for ambient sounds.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors