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

mediakitjs

v1.2.2

Published

Stop media from playing all at once.

Downloads

13

Readme

npm version licence size #💿 mediakit

Stop media elements from playing all at once. Control them with a set of universal functions.

💭 Problem

Many websites require embedded audio and video, either through HTML5 players or third party iFrames. However, managing these players can be difficult. Many audio players and iFrames can play at once, and each type of media has a different API, leading to an unpleasent experience for the user and developer.

✨ Solution

mediakit aims to provide a simple interface for controlling all the media item on your page. Simply register the name and type of each item, and you'll have access to a universal control centre for your media. By default, mediakit ensures that only one item can play at a time.

💾 Installation

📦 Packager

Install with package manager:

npm i mediakitjs

Then import as needed.

import { create, play, pauseAll } from 'mediakitjs';

🌐 CDN

Load from CDN:

<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mediakit.min.js</script>

Then grab mediakit from window.

const mk = window.mediakit;

🚀 Usage

You need to give mediakit an object containing a query selector, type and name for each media item. type and selector are required. If no name is supplied, the selector string becomes the name (including #'s and .'s).


<audio id="audio1" src="resources/music.m4a" controls></audio>
<video id="video1" src="resources/video.mp4" controls></video><br>
<iframe id="vimeo1" src="{vimeo url}" width="640" height="360"></iframe>

mk.create(
    [
        {type: 'audio', selector: '#audio1'},
        {type: 'video', selector: '#video1'},
        {type: 'vimeo', selector: '#vimeo1'},
    ],
)

📺 YouTube Usage

For Vimeo, Video, and Audio, mediakit receives a reference to the existing iFrame or media element on the page. To include a YouTube video, you must pass a selector to an empty div or span that you want to be replaced with the YouTube iFrame. This is due to the design of the YouTube iFrame API, which requires us to register the iFrame on creation. Provide the videoId in the config property.

<div id="#youtube1"></div>

...

mk.create(
    [
        {type: 'youtube', selector: '#youtube1', config: {videoId: '4eM12LJi_rg'}},
    ],
)

📖 Methods

mk.play(name)   <------------ Play an item
mk.pause(name)  <------------ Pause an item
mk.stop(name)   <------------ Stop playing an item
mk.pauseAllExcept(name)  <--- Pause all items except one
mk.pauseAll()   <------------ Pause all items

⚙️ Configuration

create() accepts a second argument for configuration. The example below shows the default values of these properties.

mk.create(
    [
        {type: 'audio', selector: '#audio1'},
        {type: 'video', selector: '#video2'},
        {type: 'vimeo', selector: '#vimeo2'},
        {type: 'youtube', selector: '#youtube1', config: {videoId: '4eM12LJi_rg'}},
    ],
    {
        playExclusive: true,
        log: false,
    }
)

Supported

  • ✅ HTML5 Audio
  • ✅ HTML5 Video
  • ✅ YouTube
  • ✅ Vimeo