Skip to Main Content
Player Logo
PlayerPlugins

Custom Assets

One of the conscious design decisions we made when building Player was to abstract away the actual asset implementation and open it up for users to bring their own when using Player. This way you can seamlessly integrate Player into your existing experiences and reuse UI assets you may have already built. Below we’ve outlined the way to build custom assets on the various platforms Player supports.

Create Your Asset

First and foremost you need to create a component to handle rendering of your asset. Without any form of transforms, the props to the component will be those from the incoming player content. It’s recommended that you attach the id, and any other html properties to the root of the asset’s tree:
const CustomAssetComp = (props) => {
  return (
    <div id={props.id} style={{ color: 'purple' }}>
      {props.text}
    </div>
  );
};
Assuming your authored JSON has a string property named text, this will render that.

Register it Using a Plugin

Now that we have a React component to render our asset, let’s create a plugin to register with Player:
class CustomAssetPlugin implements ReactPlayerPlugin{
  applyReact(reactPlayer) {
    new WebAssetProvider([['custom', CustomAssetComp]]).applyReact(reactPlayer);
  }
}
Typically you register assets by type, but the registry acts by finding the most specific partial object match. This allows you to register more specific implementations for assets of the same type.

Rendering Nested Assets

Often times, assets contain a reference or slot to another asset. For this to function properly, the custom asset needs to defer to the React Player to render the sub-asset. Say for instance we change our custom asset to now support a header property that takes another asset.
Use the ReactAsset Component from the @player-ui/react package with the nested asset as props to dynamically determine the rendering implementation to use:
import { ReactAsset } from '@player-ui/react';

const CustomAssetComp = (props) => {
  return (
    <div id={props.id} style={{ color: 'purple' }}>
      {props.header && <ReactAsset {...props.header} />}
      {props.text}
    </div>
  );
};
This would automatically find the appropriate handler for the props.header asset and use that to render.