@bbc/psammead-media-player

中文文档
6.0.10发布于 2022/04/13Apache-2.0ESM + CJS近 30 天下载 3042

Provides a media player with optional placeholder

原始使用文档
文档目录13 节
  1. Description
  2. When to use this component
  3. Installation
  4. Props
  5. CanonicalMediaPlayer
  6. AmpMediaPlayer
  7. Usage
  8. CanonicalMediaPlayer
  9. AmpMediaPlayer
  10. Accessibility notes
  11. Contributing
  12. Code of Conduct
  13. License

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.

版本与发布记录

@bbc/psammead-media-player 共发布 148 个版本,首次发布于 2019/08/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.10latest2022/04/134 年前
6.0.92022/04/084 年前
6.0.82022/03/304 年前
6.0.72022/03/294 年前
6.0.62022/03/114 年前
6.0.42022/02/104 年前

其他发布通道:alpha → 4.0.0-alpha.1。

关于 @bbc/psammead-media-player 的常见问题

@bbc/psammead-media-player 是什么?

Provides a media player with optional placeholder

如何安装 @bbc/psammead-media-player?

在项目目录运行 npm install @bbc/psammead-media-player,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.9.0)、@emotion/styled(^11.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bbc/psammead-media-player 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bbc__psammead-media-player 是否存在。

@bbc/psammead-media-player 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bbc/psammead-media-player 可以商用吗?

@bbc/psammead-media-player 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bbc/psammead-media-player 的下载量有多少?

根据 npm 官方下载统计,@bbc/psammead-media-player 在 2026/10/08 – 2026/11/06 这 30 天内被下载 3,042 次,日均约 101 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bbc/psammead-media-player 还在维护吗?

最新版本 6.0.10 发布于 2022/04/13(4 年前);至今共发布 148 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/08/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。