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

@bbc/psammead-media-player

v6.0.10

Published

Provides a media player with optional placeholder

Downloads

1,117

Readme

psammead-media-player · Known Vulnerabilities Dependency Status peerDependencies Status Storybook GitHub license npm version PRs Welcome

Description

The psammead-media-player component exports two versions of our media player: an AMP version, and an Canonical version.

At its core, this component returns an iframe that is designed to frame a media asset. The AMP variant will render an amp-iframe with a nested amp-img to use as a placeholder. The Canonical variant will render a placeholder, that when clicked will load the iframe into view.

When to use this component

This component to be used at any point on the page, specifically when a media player is needed.

Installation

npm install @bbc/psammead-media-player

Props

CanonicalMediaPlayer

| Argument | Type | Required | Default | Example | | ------------------------- | -------- | -------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | src | string | Yes | - | 'http://foobar.com/embeddable_endpoint' | | skin | string | No | 'classic' | 'audio' | | title | string | Yes | - | 'Video player' | | service | string | Yes | - | 'news' | | showPlaceholder | boolean | No | true | false | | placeholderSrc | string | No | null | 'http://foobar.com/placeholder.png' | | placeholderSrcset | string | No | '' | 'https://bbc.com/300/cat.jpg 300w, https://bbc.com/450/cat.jpg 450w, https://bbc.com/600/cat.jpg 600w' | | portrait | boolean | No | false | true | | mediaInfo | object | Yes | - | { title: 'A vertical video pretending to be a cat title', duration: '2:30', durationSpoken: '2 minutes 11 seconds', datetime: 'PT2M30S' } | | noJsClassName | string | No | null | 'no-js' | | noJsMessage | string | Yes | - | 'This media cannot play in your browser. Please enable Javascript or use a different browser.' | | onMediaInitialised | function | No | () => {} | () => hideLoadingIndicator() | | onMediaPlaying | function | No | () => {} | () => trackMediaPlaybackStarted() | | onMediaPause | function | No | () => {} | () => shrinkPlayerWindow() | | onMediaEnded | function | No | () => {} | () => trackMediaPlaybackComplete() | | onMediaPlaylistEnded | function | No | () => {} | () => visitNextVideoPage() | | onMediaError | function | No | () => {} | () => logError() |

The src prop is required, as it tells the component what page it needs to embed. The placeholderSrcset prop is not required, as it allows image responsiveness and optimization depending on the size of the screen. The title prop is required for accessibility of the embedded iframe. The portrait prop is not required, and defaults to false. This is to support portrait video content in the future. The showPlaceholder boolean prop is also not required, and defaults to true. Assuming showPlaceholder is true, the placeholderSrc will be what image to display as the placeholder. The noJsClassName is an optional prop that defaults to null and is used to add styling support to certain elements when javascript is disabled in the browser. The noJsMessage is a required prop used display a fallback text when javascript is disabled in the browser. The mediaInfo prop is required, and has the following properties.

mediaInfo

| Argument | Type | Required | Default | Example | | ----------------- | ------ | -------- | --------- | ------------------------------------------------------------------------- | | title | string | Yes | - | 'A vertical video pretending to be a cat title' | | datetime | string | No | - | 'PT11S' | | duration | string | No | - | '0:11' | | durationSpoken | string | No | - | '11 seconds' | | type | string | No | "video" | 'audio' | | guidanceMessage | string | No | - | 'May contain strong language,sexual or violent content that may offend' |

Events

The canonical media player accepts callback functions which it will invoke in response to events that are posted from the iframe. The following events are currently supported:

| Event | Description | | -----------------------| ---------------------------------------------------------------------------------| | onMediaInitialised | Called when the media player has loaded and is ready to begin playback | | onMediaPlaying | Called when the media player has started playing | | onMediaPause | Called when the user has paused playback | | onMediaEnded | Called when a playlist item (including an ad or an ident) has completed playback | | onMediaPlaylistEnded | Called when an entire playlist has completed playback | | onMediaError | Called when the media player has encountered an error |

When using the BBC's iFrame, these callbacks are invoked with a lot of additional information on the nature of the event. Internal users should refer to the SMP documentation for more details

AmpMediaPlayer

| Argument | Type | Required | Default | Example | | ------------------- | ------- | -------- | ------- | -------------------------------------------------------------------------------------------------------- | | src | string | Yes | - | http://foobar.com/embeddable_endpoint | | placeholderSrcset | string | No | null | 'https://bbc.com/300/cat.jpg 300w, https://bbc.com/450/cat.jpg 450w, https://bbc.com/600/cat.jpg 600w' | | title | string | Yes | - | Video player | | portrait | boolean | No | false | true | | placeholderSrc | string | Yes | - | 'http://foobar.com/placeholder.png' |

The placeholderSrc prop is required for AMP, as in order to have the component load an amp-iframe within 600px or 75% of the viewport from the top, we must have an amp-img placeholder. For more information on this, please refer to the AMP docs for amp-iframe.

Usage

CanonicalMediaPlayer

import { CanonicalMediaPlayer } from '@bbc/psammead-media-player';

const Container = ({
  src,
  skin,
  title,
  service,
  portrait,
  showPlaceholder,
  placeholderSrc,
  placeholderSrcset,
  mediaInfo,
  noJsClassName,
  noJsMessage,
}) => (
  <CanonicalMediaPlayer
    src={src}
    skin={skin}
    title={title}
    service={service}
    portrait={portrait}
    placeholderSrc={placeholderSrc}
    placeholderSrcset={placeholderSrcset}
    showPlaceholder={showPlaceholder}
    mediaInfo={mediaInfo}
    noJsClassName={noJsClassName}
    noJsMessage={noJsMessage}
  />
);

AmpMediaPlayer

import { AmpMediaPlayer } from '@bbc/psammead-media-player';

const Container = ({
  src,
  title,
  portrait,
  placeholderSrc,
  placeholderSrcset,
}) => (
  <AmpMediaPlayer
    src={src}
    title={title}
    portrait={portrait}
    placeholderSrc={placeholderSrc}
    placeholderSrcset={placeholderSrcset}
  />
);

Accessibility notes

The title prop is important for accessibility. It is meant for the user and should be translated to match the user's language.

Contributing

Psammead is completely open source. We are grateful for any contributions, whether they be new components, bug fixes or general improvements. Please see our primary contributing guide which can be found at the root of the Psammead respository.

Code of Conduct

We welcome feedback and help on this work. By participating in this project, you agree to abide by the code of conduct. Please take a moment to read it.

License

Psammead is Apache 2.0 licensed.