Giter Club home page Giter Club logo

ipodjs's Introduction

iPodJS

alt text

A Javascript iPod with no dependencies, have fun with it!

Demo

See the iPod in action here: http://demos.duhnnie.net/ipod/

Usage

Requirements

Either for running the demo on your machine or generate the distributable files (for use iPodJS on your own project) you will need:

  • A modern mobile/desktop web browser. iPodJS also runs on older browsers, but in some cases it will be necessary some polyfills (the ones that were excluded from the project in order to keep the code clean). More info in the Compatibility and Known Issues sections below.

  • Node.JS and NPM must be installed on the machine that will build the demo (or the distributable files).

Installation

$ npm install --save ipodjs

Using iPodJS as a module:

You can use iPodJS as an ES6, CommonJS or AMD module.

import iPodJS from 'ipodjs'; // or: const iPodJS = require('ipodjs');
import 'ipodjs/dist/ipodjs.css';

const ipod = iPodJS.create({
  skipTrackOnError: true,
  timeBeforeSkip: 5000,
  playlists: [
    {
      name: "Playlist #1",
      tracks: [
        {
          artist: "Autolux",
          title: "Change My Head",
          album: "PUSSY'S DEAD",
          artwork: "img/autolux.jpg",
          audio: "audio/change_my_head.mp3"
        },
        {
          artist: "Grouplove",
          title: "Borderlines and Aliens",
          album: "Spreading Rumors",
          artwork: "img/grouplove.jpg",
          audio: "audio/borderlines.mp3"
        }
      ]
    },
    {
      name: "Playlist #2",
      tracks: [
        {
          artist: "NOFX",
          title: "Linoleum",
          album: "Punk in Drublic",
          artwork: "img/nofx.jpg",
          audio: "audio/linoleum.mp3"
        },
        {
          artist: "Radiohead",
          title: "Airbag",
          album: "OK Computer",
          artwork: "img/radiohead.jpg",
          audio: "audio/airbag.mp3"
        }
      ]
    }
  ]
});

document.body.appendChild(ipod.getHTML());

Using iPodJS directly in HTML

There are some issues in some browsers due the lack of some browser ES6 implemented functions (like Array.from()). For more info about it read the Compatibility and Known Issues sections below.

Usage Example:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <link rel="stylesheet" href="css/ipodjs.css"/>
    <script src="js/ipod.js"></script>
    <script>
      document.addEventListener('DOMContentLoaded', () => {

        const ipod = iPodJS.create({
          skipTrackOnError: true,
          timeBeforeSkip: 5000,
          playlists: [
            {
              name: "Playlist #1",
              tracks: [
                {
                  artist: "Autolux",
                  title: "Change My Head",
                  album: "PUSSY'S DEAD",
                  artwork: "img/autolux.jpg",
                  audio: "audio/change_my_head.mp3"
                },
                {
                  artist: "Grouplove",
                  title: "Borderlines and Aliens",
                  album: "Spreading Rumors",
                  artwork: "img/grouplove.jpg",
                  audio: "audio/borderlines.mp3"
                }
              ]
            },
            {
              name: "Playlist #2",
              tracks: [
                {
                  artist: "NOFX",
                  title: "Linoleum",
                  album: "Punk in Drublic",
                  artwork: "img/nofx.jpg",
                  audio: "audio/linoleum.mp3"
                },
                {
                  artist: "Radiohead",
                  title: "Airbag",
                  album: "OK Computer",
                  artwork: "img/radiohead.jpg",
                  audio: "audio/airbag.mp3"
                }
              ]
            }
          ]
        });

        document.body.appendChild(ipod.getHTML());
      });
    </script>
    <title>My iPod</title>
  </head>
  <body></body>
</html>

Compatibility

Since iPodJS is built using Babel, it is compatible with modern browsers and older ones. However, to keep the project code clean, some browser-core function polyfills were not included on the distributable files. So, in production polyfills for some unimplemented browser functions must be applied (Babel).

Known issues

For Microsoft IE11/Edge it is necessary to apply some polyfills to solve some issues:

  • Edge doesn't have a promise-like implementation of the Audio.play() method. A dirty polyfill is being used ONLY for the demo using the npm run start command. For production the polyfill must be applied manually or by using some tool (Babel), since the distribuitable code doesn't include the browser-function polyfills.
// This is a polyfill to allow a good demo in IE/non-Chromium Edge, since they not have a promise-like implementation
//on Audio object, in production use some pollyfill package. Different versions for this polyfill can be used.
Audio.prototype.play =  (function () {
    const originalFn = Audio.prototype.play;

    return function () {
        let resp,
            error;

        try {
            resp = originalFn.apply(this, arguments);
        } catch (e) {
            error = true;
        }
        
        if (resp && resp.catch) {
            return resp;
        } else {
            return {
                catch: function (fn) {
                    if (error) {
                        fn(error || {});    
                    }
                }
            };
        }
    };
}) ();
  • IE11 has issues with Array.from() method, it needs to be polyfilled to make the iPodJS work.

Happy listening!

ipodjs's People

Contributors

duhnnie avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.