Git Product home page Git Product logo

imaginary-player's Introduction

imaginary-player

npm module for pseudo-streaming/broadcasting

Build Status

Motivation

Broadcasting is a complex problem (such that every visitor would be sychronized to watch the same moment). Luckly with HTML5 <video> and Media Fragments URI, the client can do most of this work -- we just need to supply where something is currently playing. ๐Ÿ˜Ž Hence this module is a fancy timer in essence. See below for HTML <video> support.

Usage examples

First things first. Install the package.

npm install imaginary-player [--save]

You will need to initialize the playlist like below. Each playlist item can be your arbitrary data but it must respond to the duration property.

var player = require('imaginary-player');

player.playlist([
  { duration: '31:29', title: 'All Arsenal Goals 2012/13',                        location: '1.webm' },
  { duration: '15:00', title: 'The Greatest Ever Arsenal Player - Thierry Henry', location: '2.webm' },
  { duration: '8:17',  title: 'Kieran Gibbs - Still Breathing (2012/13)',         location: '3.webm' }
]).play();

Alternatively, you can defer calling play() until later. play() will start playing from the beginning of the playlist and loop.

player.play();

You can also specify which index it should start playing from. play() is equivalent to play(0).

player.play(1);

Specify which attribute should show up in the logs:

player.logAttribute('title');
// 1371408021917 now playing: All Arsenal Goals 2012/13

Instead of playing in the order of the original playlist, the player can shuffle at the beginning of each playthrough. This is nice for when your media playlist becomes much too predictable.

player.shuffle(true);
// at the beginning, shuffling...
// 1371408021917 now playing: The Greatest Ever Arsenal Player - Thierry Henry

Once you have it playing, you can now() ask for what/where it's currently playing. Using the popular web application framework express, you can serve that information like below:

var express = require('express');

var app = express();

app.get('/where', function(req, res) {
  res.send( player.now() );
});

app.listen(3000);

This would produce a response like below. The played attribute represents the current playing marker in seconds.

{
  "duration": "31:29",
  "title": "All Arsenal Goals 2012/13",
  "location": "1.webm",
  "played": 589.743
}

Your client can then consume that information like so:

var screen = document.querySelector('your-<video>-element'); // with autoplay attribute maybe?

var now = res.body; // server-returned response
screen.src = now.location + "#t=" + now.played;

About HTML5 video support

I'm not a video / encoding format expert. This article from diveintohtml5 gives good insight. ####tl;dr

  • .webm (VP8 + Vorbis)
  • .mp4 (H.264 + AAC)
  • .ogg (Theora + Vorbis)

Fun facts

By coincidence ๐Ÿ˜‰, Jay-Z has an awesome track named Imaginary Player.

imaginary-player's People

Contributors

mjchoi avatar

Watchers

hisky.blogger 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.