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

tunes

v0.6.1

Published

HTML5 audio and video playlists

Downloads

11

Readme

Tunes

HTML5 <audio> and <video> playlists

Tunes (formerly cue) is an opensource jQuery plugin that uses JSON and data attributes to make HTML5 audio and video playlists possible.

Goals

  1. Provide semantic storage and performant access to playlist data.
  2. Provide succinct semantic controls that can be styled in CSS.
  3. Be minimal, but extensible.

Types

Compatibility: the more filetypes, the better

Full coverage in modern browsers requires 2+ types

URIs

  • To simplify the examples, most of the file URIs shown are relative. In production you probably want to use full URIs.
  • AJAX-loaded .json files must be on the same domain due to cross-domain restrictions.

API (0.6)

[data-tunes]

[data-tunes] is the data attribute in which the JSON playlist is stored. It is designed to be placed on a container element that holds the media element and related informational elements such as credits or captions. It can contain inline JSON or the filename of a .json file to load via AJAX. Inline JSON is more performant and more stable than loading AJAX requests.

<div data-tunes="playlist.json">
    <video controls>
        <source src="default.mp4" type="video/mp4">
        <source src="default.webm" type="video/webm">
    </video>
</div>

[data-tunes-insert]

[data-tunes-insert] makes it possible to insert values from the properties in your media object into your HTML.

<figure data-tunes="playlist.json">
    <video controls>
        <source src="default.mp4">
        <source src="default.webm">
    </video>
    <figcaption data-tunes-insert="caption">
        Caption for the default video. The value of the "caption"
        property gets inserted here when the video changes.
    </figcaption>
</figure>

[data-tunes-attr]

[data-tunes-attr] makes it possible to update arbitrary HTML attributes based on the properties in your media object. It takes a JSON object that maps attribute names to the property names from the media object that should fill them.

<figure data-tunes="playlist.json">
    <video controls>
        <source src="default.mp4">
        <source src="default.webm">
        <p>
            To watch this video please <a href="http://browsehappy.com">updgrade your browser</a>
            or <a href="default.mp4" data-tunes-attr='{"href": "mp4"}'>download the .mp4</a>
        </p>
    </video>
</figure>

JSON

The format for the JSON playlist data is an array of media objects containing data about each media file. Please validate your JSON to prevent syntax errors. The media objects provide several capabilities. A simple <video> example would look something like this:

[{
    "mp4": "identity.mp4"
  , "webm": "identity.webm"
 },{
    "mp4": "supremacy.mp4"
  , "webm": "supremacy.webm"
 },{
    "mp4": "ultimatum.mp4"
  , "webm": "ultimatum.webm"
}]

Alternate syntax: You can achieve the same as above by setting the src property to an array of URIs. If you mix the 2 syntaxes, the named extension props take precedence over the src prop. In either case tunes will choose the most appropriate file based on the feature detection.

[{
    "src": ["identity.mp4", "identity.webm"]
 },{
    "src": ["supremacy.mp4", "supremacy.webm"]
 },{
    "src": ["ultimatum.mp4", "ultimatum.webm"]
}]

In your media objects, you can include whatever extra properties you want for use with [data-tunes-insert] and/or [data-tunes-attr]. The purpose of these attributes is to enable you to include relavent credits, captions, or links.

[{
    "mp4": "identity.mp4"
  , "webm": "identity.webm"
  , "title": "The Bourne Identity"
  , "imbd": "http://www.imdb.com/title/tt0258463/"
 },{
    "mp4": "supremacy.mp4"
  , "webm": "supremacy.webm"
  , "title": "The Bourne Supremacy"
  , "imdb": "http://www.imdb.com/title/tt0372183/"
 },{
    "mp4": "ultimatum.mp4"
  , "webm": "ultimatum.webm"
  , "title": "The Bourne Ultimatum"
  , "imdb": "http://www.imdb.com/title/tt0440963/"
}]

MIME types

To play media files, your server must recognize the correct MIME types.

Make sure your .htaccess includes these rules (via H5BP)
# MIME types for audio and video files
AddType audio/mp4                      m4a f4a f4b
AddType audio/ogg                      oga ogg
AddType video/mp4                      mp4 m4v f4v f4p
AddType video/ogg                      ogv
AddType video/webm                     webm
AddType video/x-flv                    flv

Fallbacks

Fallbacks and graceful degradation for pre-HTML5 browsers are possible through smart use of [data-tunes-insert] and [data-tunes-attr]. It's a vanilla diet approach and no Flash is used.

Troubleshoot

  1. Does your JSON validate? Use: jsonlint.com
  2. Does your HTML validate? Use: html5.validator.nu
  3. Did jQuery load? Is it version 1.7 or higher? jQuery must run before tunes.
  4. Are there any JavaScript errors in the console?
  5. Is your server configured to serve the correct MIME types? See section above.
  6. Are your URIs correct? AJAX-loaded playlists must be on the same server.
  7. Ask @ryanve or submit an issue.

Dependencies

Requires jQuery 1.7+ or an ender build that implements compatible versions of:

  • $()
  • $.ajax() *needed only for AJAX playlists
  • $.contains()
  • $.get() *needed only for AJAX playlists
  • $.fn.on()
  • $.fn.addClass()
  • $.fn.attr()
  • $.fn.children()
  • $.fn.empty()
  • $.fn.find()
  • $.fn.html()
  • $.fn.insertAfter()
  • $.fn.ready()
  • $.fn.removeAttr()
  • $.fn.removeClass()

Resources

License: MIT

Copyright (C) 2013 by Ryan Van Etten