Getting Started with Brightcove Web & Smart TV SDK

This section provides the initial steps required to set up and begin using the Brightcove Web & Smart TV SDK.

Installing the SDK

You can install the Brightcove Web & Smart TV SDK using npm or directly from the Brightcove CDN.


Using npm:

Open your command line interface and run the following command to install the SDK:

npm install @brightcove/web-sdk


Using CDN:

Alternatively, if you prefer to use the SDK from the CDN, include the following script tag in your HTML files:

<script src="https://players.brightcove.net/web-sdk/1/index.js"></script>


Creating a Media Player

Once the SDK is installed, you can create a media player to embed in your application. By following these steps, you will have a basic video player set up using the Brightcove Web & Smart TV SDK.

  1. Import the Player (with UI) class from the Brightcove SDK:

    import { Player } from '@brightcove/web-sdk';
            
  2. Create a Player Instance:

    const player = new Player();
            
  3. Set up the player with your Brightcove account details:

    player.updateConfiguration({
      brightcove: {
        accountId: 'your-account-id',
        auth: { policyKey: 'your-policy-key' }
      }
    });
            
  4. Link the player to a video element:

    const videoElement = document.querySelector('video');
    player.attach(videoElement);
            
  5. Load a video by its ID from the Brightcove Playback API:

    const { promise } = player.getVideoById({ videoId: 'your-video-id' });
    promise.then((videoModel) => player.loadVideoModel(videoModel));
                
                        
Final code:
// Import the Player (with UI) class from the Brightcove SDK
import { Player } from '@brightcove/web-sdk';

// Create a new player
const player = new Player();

// Update the player's configuration
player.updateConfiguration({
  brightcove: {
    accountId: 'your-account-id',
    auth: { policyKey: 'your-policy-key' }
  }
});

// Attach a video element to the Player instance
const videoElement = document.querySelector('video');
player.attach(videoElement);
    
// Load a video by its ID from the Brightcove Playback API
const { promise } = player.getVideoById({ videoId: 'your-video-id' });
promise.then((videoModel) => player.loadVideoModel(videoModel));