Skip to content

opendevise/bespoke-multimedia

Repository files navigation

bespoke-multimedia

npm package Build Status (Travis CI)

Toggles playback of audio and (native, Vimeo or YouTube) video, toggles or restarts animations in SVGs and restarts animated GIFs in a Bespoke.js presentation.

Example

View the demo online.

This repository includes a demo folder that shows this plugin in action. To view it locally, you first need to clone this repository:

$ git clone https://github.com/opendevise/bespoke-multimedia && cd bespoke-multimedia

Next, install the dependencies inside the project folder using npm:

$ npm install

Finally, visit the file demo/index.html in your browser and navigate between slides to see the multimedia playback in action.

Download

Download the production mode version or the development mode version, or use a package manager.

npm

$ npm install bespoke-multimedia

Bower

$ bower install bespoke-multimedia

Usage

This plugin is shipped in a UMD format, meaning it is available as a CommonJS/AMD module or as a browser global.

For example, when using CommonJS modules:

var bespoke = require('bespoke'),
  multimedia = require('bespoke-multimedia');

bespoke.from('.deck', [
  multimedia()
]);

When using browser globals:

bespoke.from('.deck', [
  bespoke.plugins.multimedia()
]);

Options

This plugin does not currently expose any general options. However, each component has options that can be set using custom attributes.

Custom Attributes for Media Elements

data-rewind (type: boolean, default: false)

If this attribute is present, the media stream is restarted each time playback is triggered.

data-volume (type: integer, range: 0-10)

This attribute can be used to set the volume of the media stream. The value must be an integer between 0 (muted) and 10 (full volume). Any value outside this range will be coerced to the closest range limit. If this attribute is not specified, the volume of the media stream remains unmodified.

Custom Attributes for Image Elements

data-reload (type: boolean, default: false)

If present, instructs the plugin to reload the image by reassigning the main URL attribute (src for GIF, data for SVG).

Behavior

This plugin automatically plays all multimedia on the active slide, then later pauses it when the slide becomes inactive. The definition of “play” and “pause” depends on the media type.

The supported media types are:

The following sections describe how each media type is handled.

Native HTML Audio

All audio elements on the active slide are played automatically when the slide is activated. When the slide is deactivated, the audio is paused.

Options

You can use (most of) the built-in attributes supported by the <audio> element, such as preload and loop.

🔥
Using the autoplay and volume attributes is not recommended since they conflict with the behavior of this plugin.

In addition to the built-in attributes, this plugin also recognizes the custom attributes defined in Custom Attributes for Media Elements.

Example

<audio src="clearday.ogg" preload="auto" loop="true" data-volume="2" data-rewind></audio>

Native HTML Video

All video elements on the active slide are played automatically when the slide is activated. When the slide is deactivated, the videos are paused.

⚠️
If the MIME type for the video is not set correctly on the server, the video may not appear. This restriction may be unique to Firefox.

Options

You can use (most of) the built-in attributes supported by the <video> element, such as controls, preload and loop.

🔥
Using the autoplay attribute is not recommended since it conflicts with the behavior of this plugin.

In addition to the built-in attributes, this plugin also recognizes the custom attributes defined in Custom Attributes for Media Elements.

Example

<video src="shapes.mp4" preload="auto" loop="true"></video>

Vimeo Video

All Vimeo videos on the active slide are played automatically when the slide is activated using Vimeo’s Universal JavaScript API. When the slide is deactivated, the videos are paused.

⚠️
Video playback only works if the presentation is viewed through a web server.

In order for the plugin to control Vimeo videos via the JavaScript API (and also distinguish between multiple videos), for each video, you must:

  1. Include an id attribute on the <iframe> element.

  2. Add player_id=PLAYER_ID to the query string of the video URL, where PLAYER_ID is the value of the id attribute.

  3. Add api=1 to the query string of the video URL.

  4. Add autoplay=0 to the query string of the video URL.

Refer to the example later in this section for details.

Options

You can use (most of) the universal parameters supported by the Vimeo player, such as background and loop.

💡
At the time of writing, the background parameter was not yet documented. If you set this parameter to 1, Vimeo will hide all the controls. This setting provides an emersive playback experience, ideal for a presentation slide. Note, however, that the video is muted by default in background mode. If your video has sound, and you want the sound to be heard, you must specify the data-volume attribute.

This plugin also recognizes the custom attributes defined in Custom Attributes for Media Elements.

Example

<iframe id="shapes" src="https://player.vimeo.com/video/18270184?player_id=shapes&amp;api=1&amp;autoplay=0&amp;background=1" frameborder="0" allowfullscreen></iframe>

YouTube Video

All YouTube videos on the active slide are played automatically when the slide is activated using YouTube’s IFrame API. When the slide is deactivated, the videos are paused.

In order for the plugin to control YouTube videos via the JavaScript API, for each video, you must:

  1. Add enablejsapi=1 to the query string of the video URL.

  2. Add autoplay=0 to the query string of the video URL.

Refer to the example later in this section for details.

Options

You can use (most of) the player parameters supported by the YouTube player, such as controls, loop and rel.

In order for the loop parameter to take effect, you must specify the playlist parameter with a value equal to the value of the id attribute.

This plugin also recognizes the custom attributes defined in Custom Attributes for Media Elements.

Example

<iframe width="640" height="360" src="https://www.youtube.com/embed/AV3kYPutYfs?rel=0&amp;showinfo=0&amp;controls=0&amp;enablejsapi=1&amp;autoplay=0" frameborder="0" allowfullscreen></iframe>

Animated SVG

All SVGs on the active slide that are embedded using an <object> element are automatically either reloaded or marked active (depending on how the SVG is configured) when the slide is activated. When the slide is deactivated, any SVG previously marked active is marked inactive.

If the data-reload attribute is present on the <object> element, the plugin forces the browser to reload the SVG by reassigning the data attribute. This should cause any animations defined in the SVG to restart.

If the data-reload attribute is not present, and the SVG DOM is reachable using JavaScript, the active CSS class is toggled on the root SVG element. In this case, the animation must be configured to restart by way of a CSS rule.

Options

This plugin recognizes the custom attributes defined in Custom Attributes for Image Elements.

📎
If the data-reload attribute is not present, the plugin instead toggles the CSS class on the root element of the SVG.
⚠️
The CSS class can only be toggled on the root element if the SVG is loaded from the same domain (i.e., same-origin policy). When the SVG is loaded from a different domain, you must add the data-reload attribute.

Example

<object data="orange-circle.svg" type="image/svg+xml"></object>

where the SVG orange-circle.svg has the following content:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 100">
<style>
svg.active:root #orange-circle { animation: 5s linear 0s normal forwards 1 running coast }
@keyframes coast { 100% { transform: translateX(400px) } }
</style>
<circle id="orange-circle" r="30" cx="50" cy="50" fill="orange"/>
</svg>

Animated GIF

All GIFs that have a data-reload attribute on the active slide are automatically reloaded when the slide is activated. No action is taken when the slide is deactivated.

The plugin forces the browser to reload the SVG by reassigning the src attribute. This should cause the GIF animation to restart.

Options

This plugin recognizes the custom attributes defined in Custom Attributes for Image Elements.

📎
If the data-reload attribute is not present, the plugin takes no action on the GIF.

Example

<img src="http://i.giphy.com/90F8aUepslB84.gif" data-reload>

License

About

Toggles playback of multimedia and SVG animations in a Bespoke.js presentation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published