6.0.10 • Published 2 years ago

@bbc/psammead-media-player v6.0.10

Weekly downloads
1,487
License
Apache-2.0
Repository
github
Last release
2 years ago

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

ArgumentTypeRequiredDefaultExample
srcstringYes-'http://foobar.com/embeddable_endpoint'
skinstringNo'classic''audio'
titlestringYes-'Video player'
servicestringYes-'news'
showPlaceholderbooleanNotruefalse
placeholderSrcstringNonull'http://foobar.com/placeholder.png'
placeholderSrcsetstringNo'''https://bbc.com/300/cat.jpg 300w, https://bbc.com/450/cat.jpg 450w, https://bbc.com/600/cat.jpg 600w'
portraitbooleanNofalsetrue
mediaInfoobjectYes-{ title: 'A vertical video pretending to be a cat title', duration: '2:30', durationSpoken: '2 minutes 11 seconds', datetime: 'PT2M30S' }
noJsClassNamestringNonull'no-js'
noJsMessagestringYes-'This media cannot play in your browser. Please enable Javascript or use a different browser.'
onMediaInitialisedfunctionNo() => {}() => hideLoadingIndicator()
onMediaPlayingfunctionNo() => {}() => trackMediaPlaybackStarted()
onMediaPausefunctionNo() => {}() => shrinkPlayerWindow()
onMediaEndedfunctionNo() => {}() => trackMediaPlaybackComplete()
onMediaPlaylistEndedfunctionNo() => {}() => visitNextVideoPage()
onMediaErrorfunctionNo() => {}() => 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

ArgumentTypeRequiredDefaultExample
titlestringYes-'A vertical video pretending to be a cat title'
datetimestringNo-'PT11S'
durationstringNo-'0:11'
durationSpokenstringNo-'11 seconds'
typestringNo"video"'audio'
guidanceMessagestringNo-'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:

EventDescription
onMediaInitialisedCalled when the media player has loaded and is ready to begin playback
onMediaPlayingCalled when the media player has started playing
onMediaPauseCalled when the user has paused playback
onMediaEndedCalled when a playlist item (including an ad or an ident) has completed playback
onMediaPlaylistEndedCalled when an entire playlist has completed playback
onMediaErrorCalled 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

ArgumentTypeRequiredDefaultExample
srcstringYes-http://foobar.com/embeddable_endpoint
placeholderSrcsetstringNonull'https://bbc.com/300/cat.jpg 300w, https://bbc.com/450/cat.jpg 450w, https://bbc.com/600/cat.jpg 600w'
titlestringYes-Video player
portraitbooleanNofalsetrue
placeholderSrcstringYes-'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.

6.0.10

2 years ago

6.0.7

2 years ago

6.0.6

2 years ago

6.0.9

2 years ago

6.0.8

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.4

2 years ago

5.1.14

2 years ago

5.1.13

3 years ago

5.1.12

3 years ago

5.1.9

3 years ago

5.1.11

3 years ago

5.1.10

3 years ago

5.1.8

3 years ago

5.1.7

3 years ago

5.1.6

3 years ago

5.1.5

3 years ago

5.1.4

3 years ago

5.1.3

3 years ago

5.1.2

3 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.32

3 years ago

5.0.31

3 years ago

5.0.30

3 years ago

5.0.29

3 years ago

5.0.28

3 years ago

5.0.25

3 years ago

5.0.26

3 years ago

5.0.27

3 years ago

5.0.24

3 years ago

5.0.23

3 years ago

5.0.21

3 years ago

5.0.22

3 years ago

5.0.20

3 years ago

5.0.19

3 years ago

5.0.17

3 years ago

5.0.18

3 years ago

5.0.16

3 years ago

5.0.14

3 years ago

5.0.15

3 years ago

5.0.13

3 years ago

5.0.12

3 years ago

5.0.11

3 years ago

5.0.10

3 years ago

5.0.9

3 years ago

5.0.8

3 years ago

5.0.7

3 years ago

5.0.6

3 years ago

5.0.5

4 years ago

5.0.4

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

5.0.0

4 years ago

4.0.2

4 years ago

4.0.0-alpha.1

4 years ago

4.0.1

4 years ago

4.0.0-alpha.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.10.1

4 years ago

2.10.2

4 years ago

2.10.0

4 years ago

2.9.0

4 years ago

2.8.2

4 years ago

2.8.0

4 years ago

2.7.16

4 years ago

2.7.15

4 years ago

2.7.14

4 years ago

2.7.13

4 years ago

2.7.12

4 years ago

2.7.11

4 years ago

2.7.10

4 years ago

2.7.9

4 years ago

2.7.8

4 years ago

2.7.7

4 years ago

2.7.6

4 years ago

2.7.5

4 years ago

2.7.4

4 years ago

2.7.3

4 years ago

2.7.2

4 years ago

2.7.1

4 years ago

2.7.0

4 years ago

2.6.4

4 years ago

2.6.3

4 years ago

2.6.2

4 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.5.4

4 years ago

2.5.3

4 years ago

2.5.2

4 years ago

2.5.1

4 years ago

2.5.0

4 years ago

2.4.5

4 years ago

2.4.4

4 years ago

2.4.3

4 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.8

4 years ago

2.3.7

4 years ago

2.3.6

4 years ago

2.3.5

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.7

4 years ago

2.2.6

4 years ago

2.2.5

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

5 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.1-alpha.8

5 years ago

1.1.1-alpha.7

5 years ago

1.1.1-alpha.6

5 years ago

1.1.1-alpha.5

5 years ago

1.1.1-alpha.4

5 years ago

1.1.1-alpha.3

5 years ago

1.1.1-alpha.2

5 years ago

1.1.1-alpha.1

5 years ago

1.1.0-alpha.1

5 years ago

1.0.1-alpha.4

5 years ago

1.0.1-alpha.3

5 years ago

1.0.1-alpha.2

5 years ago

1.0.1-alpha.1

5 years ago

1.0.1-alpha.0

5 years ago

1.0.0-alpha.0

5 years ago