6.1.1 • Published 1 month ago

@project-sunbird/sunbird-video-player-v9 v6.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

The Video player library for Sunbird platform!

The Video player library is powered by Angular. This player is primarily designed to be used on Sunbird consumption platforms (mobile app, web portal, offline desktop app) to drive reusability and maintainability, hence reducing the redundant development effort significantly, and it can be integrated with any platform irrespective of the platforms and the frontend frameworks. It is exported not only as an angular library but also as a web component. 

Getting Started with different integrations steps

The video player can be integrated as a web component and also as an angular library in angular application projects and it can also be integrated into any mobile framework as a web component.

Use as web components

Any web based application can use this library as a web component. It accepts player config as input and triggers player and telemetry events back to the application.

Import this library in any web application and use the custom component.

Follow below-mentioned steps to use it in plain javascript project:

  • Insert library as below:
    	```javascript
    	<script type="text/javascript" src="sunbird-video-player.js"></script>
    	```
  • Create a asset folder and copy all the files from here, library requires these assets internally to work well.
  • Get sample playerConfig from here: playerConfig

  • Pass the QuestionListAPI baseUrl if your content is interactive otherwise you can skip this step for eg.

    	```javascript

    window.questionListUrl = 'https://staging.sunbirded.org/api/question/v1/list'; window.questionSetBaseUrl = 'https://staging.sunbirded.org/api/questionset';

  • Create a custom html element: sunbird-video-player

    	```javascript

    const videoElement = document.createElement('sunbird-video-player');

  • Pass data using player-config

    	```javascript
    	videoElement.setAttribute('player-config', JSON.stringify(playerConfig));
    	```
    
    	**Note:** Attribute should be in **string** type
  • Listen for the output events: playerEvent and telemetryEvent

    	```javascript
    	videoElement.addEventListener('playerEvent', (event) => {
    		console.log("On playerEvent", event);
    	});
    	videoElement.addEventListener('telemetryEvent', (event) => {
    		console.log("On telemetryEvent", event);
    	});
    	```
  • Append this element to existing element

    	```javascript
    	const  myPlayer = document.getElementById("my-player");
    	myPlayer.appendChild(qumlPlayerElement);
    	```
  • Refer demo example

Use as Web component in the Angular app

  • Run command

      npm i @project-sunbird/sunbird-video-player-web-component
      npm i reflect-metadata
  • Add these entries in angular json file inside assets, scripts and styles like below

              "assets": [
                "src/favicon.ico",
                "src/assets",
                {
                  "glob": "**/*.*",
                  "input": "./node_modules/@project-sunbird/sunbird-video-player-web-component/assets",
                  "output": "/assets/"
                }
              ],
              "styles": [
                "src/styles.scss",
                "node_modules/@project-sunbird/sunbird-video-player-web-component/styles.css"
              ],
              "scripts": [
                "node_modules/reflect-metadata/Reflect.js",
                "node_modules/@project-sunbird/sunbird-epub-player-web-component/sunbird-video-player.js"
              ]
  • Import CUSTOM_ELEMENTS_SCHEMA in app module and add it to the NgModule as part of schemas like below

    	```javascript

    ... import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; ...

    @NgModule({ ... schemas: CUSTOM_ELEMENTS_SCHEMA, ... })

    	```
  • Integrating sunbird-video-player web component in angular component

    Create a viewChild in html template of the angular component like

        <div #video></div>

    Refer the viewChild in ts file of the component and create the video player using document.createElement, then attach the player config and listen to the player and telemetry events like below and since we are rendering using viewChild these steps should be under ngAfterViewInit hook of the angular component.

....

@ViewChild('video') video: ElementRef;

  ....
 ngAfterViewInit() {
    const playerConfig = <Config need be added>;
      const epubElement = document.createElement('sunbird-video-player');
      epubElement.setAttribute('player-config', JSON.stringify(playerConfig));

      epubElement.addEventListener('playerEvent', (event) => {
        console.log("On playerEvent", event);
      });

      epubElement.addEventListener('telemetryEvent', (event) => {
        console.log("On telemetryEvent", event);
      });
      this.video.nativeElement.append(epubElement);
  }
  ....

Note: : Click to see the mock - playerConfig and send input config as string

Use as Angular library in angular app

Step 1: Installation

Just run the following:

ng add @project-sunbird/sunbird-video-player-v9

It will install sunbird-video-player for the default application specified in your angular.json. If you have multiple projects and you want to target a specific application, you could specify the --project option

ng add @project-sunbird/sunbird-video-player-v9 --project myProject

Manual installation

If you prefer not to use schematics or want to add sunbird-video-player-v9 to an older project, you'll need to do the following:

  npm install @project-sunbird/sunbird-video-player-v9 --save
  npm install @project-sunbird/sunbird-quml-player-v9 --save
  npm install @project-sunbird/sb-styles --save
  npm install @project-sunbird/client-services --save
  npm install lodash-es --save
  npm install ngx-bootstrap --save
  npm install jquery --save
  npm install video.js --save
  npm install videojs-contrib-quality-levels --save
  npm install videojs-http-source-selector --save

2: Include the styles, scripts and assets in angular.json

"styles": [
...
...
"src/styles.css",
"./node_modules/@project-sunbird/sb-styles/assets/_styles.scss",
"./node_modules/video.js/dist/video-js.min.css",
"./node_modules/@project-sunbird/sunbird-video-player-v9/lib/assets/videojs.markers.min.css",
"./node_modules/videojs-http-source-selector/dist/videojs-http-source-selector.css"
],
"scripts": [
...
...
"node_modules/jquery/dist/jquery.min.js",
"node_modules/video.js/dist/video.js",
"node_modules/@project-sunbird/sunbird-video-player-v9/lib/assets/videojs-markers.js",
"node_modules/videojs-contrib-quality-levels/dist/videojs-contrib-quality-levels.min.js",
"node_modules/videojs-http-source-selector/dist/videojs-http-source-selector.min.js"
]

Add following under architect.build.assets

 {
    ...
    "build": {
    
    "builder": "@angular-devkit/build-angular:browser",
    
    "options": {
	    ...
	    ...

	    "assets": [
	    
		   ...
		   ...
		    
		    {
			    "glob": "**/*.*",
			    "input": "./node_modules/@project-sunbird/sunbird-video-player-v9/lib/assets/",
			    "output": "/assets/"
		    },
      {
            "glob": "**/*",
            "input": "node_modules/@project-sunbird/sunbird-quml-player-v9/lib/assets/",
            "output": "/assets/"
      }
	    
	    ],

    "styles": [
    
    ...
    
    "./node_modules/@project-sunbird/sb-styles/assets/_styles.scss",
    "./node_modules/video.js/dist/video-js.min.css",
    "./node_modules/@project-sunbird/sunbird-video-player-v9/lib/assets/videojs.markers.min.css",
    "./node_modules/videojs-http-source-selector/dist/videojs-http-source-selector.css"
    ],
    "scripts": [
     ...
     "node_modules/jquery/dist/jquery.min.js",
     "node_modules/video.js/dist/video.js",
     "node_modules/@project-sunbird/sunbird-video-player-v9/lib/assets/videojs-markers.js",
     "node_modules/videojs-contrib-quality-levels/dist/videojs-contrib-quality-levels.min.js",
     "node_modules/videojs-http-source-selector/dist/videojs-http-source-selector.min.js",
     "dist/sunbird-video-player/lib/assets/videojs-transcript-click.min.js"
     ]
    ...
    ...

},

Step 2: Import the modules and components

Import the NgModule where you want to use. Also create a question-cursor-implementation.service

    import { SunbirdVideoPlayerModule } from '@project-sunbird/sunbird-video-player-v9';
    import { QuestionCursor } from '@project-sunbird/sunbird-quml-player-v9';
    import { QuestionCursorImplementationService } from './question-cursor-implementation.service';

    
    @NgModule({
	    ...
	    
	    imports: [SunbirdVideoPlayerModule],
	    providers: [{ provide: QuestionCursor, useClass: QuestionCursorImplementationService }],
	    
	    ...
    })

  
    export class TestAppModule { }

  

Step 3: Send input to render VIDEO player

Use the mock config in your component to send input to VIDEO player Click to see the mock - playerConfig

Player config

var playerConfig = {
  "context": {
    "mode": "play",  // To identify preview used by the user to play/edit/preview
    "authToken": "", // Auth key to make  api calls
    "sid": "7283cf2e-d215-9944-b0c5-269489c6fa56", // User sessionid on portal or mobile 
    "did": "3c0a3724311fe944dec5df559cc4e006", // Unique id to identify the device or browser 
    "uid": "anonymous", // Current logged in user id
    "channel": "505c7c48ac6dc1edc9b08f21db5a571d", // Unique id of the channel(Channel ID)
    "pdata": {
      "id": "sunbird.portal", // Producer ID. For ex: For sunbird it would be "portal" or "genie"
      "ver": "3.2.12", // Version of the App
      "pid": "sunbird-portal.contentplayer" // Optional. In case the component is distributed, then which instance of that component
    },
    "contextRollup": { // Defines the content roll up data
      "l1": "505c7c48ac6dc1edc9b08f21db5a571d"
    },
    "tags": [ // Defines the tags data
      ""
    ],
    "cdata": [], // Defines correlation data
    "timeDiff": 0,  // Defines the time difference
    "objectRollup": {}, // Defines the object roll up data
    "host": "", // Defines the from which domain content should be load
    "endpoint": "", // Defines the end point
    "userData": {  // Defines the user data firstname & lastname
      "firstName": "",
      "lastName": ""
    }
  },
  "config": { 
	"traceId": "afhjgh", // Defines trace id
    "sideMenu": { 
      "showShare": true,    // show/hide share button in side menu. default value is true
      "showDownload": true, // show/hide download button in side menu. default value is true
      "showReplay": true, // show/hide replay button in side menu. default value is true
      "showExit": true,   // show/hide exit button in side menu. default value is true
    },
       // tslint:disable-next-line:max-line-length
    "transcripts": [] // for default selection we need this , ex: ['kn', 'en'] the last element in the array will be used for default selection and no need of default selection than no need send this in config or send empty array [] or ['off'] 
  },
  "metadata": { // Content metadata json object (from API response take -> response.result.content)
  "transcripts": [] // Defines the details of the transcripts data array and each object in array conatins details of language,languageCode, identifier, artifactUrl of each transcript
  }, 
}        

Telemetry property description

Property NameDescriptionDefault Value
contextIt is an object it contains the uid,did,sid,mode etc., these will be logged inside the telemetry{}
modeIt is string to identify preview used by the user to play/edit/previewplay
authTokenIt is string and Auth key to make api calls''
sidIt is string and User sessionid on portal or mobile''
didIt is string and Unique id to identify the device or browser''
uidIt is string and Current logged in user id''
channelIt is string which defines channel identifier to know which channel is currently using.in.sunbird
pdataIt is an object which defines the producer information it should have identifier and version and canvas will log in the telemetry{'id':'in.sunbird', 'ver':'1.0'}
contextRollupIt is an object which defines content roll up data{}
tagsIt is an array which defines the tag data[]
objectRollupIt is an object which defines object rollup data{}
hostIt is string which defines the from which domain content should be loadwindow.location.origin
userDataIt is an object which defines user data{}
cdataIt is an array which defines the correlation data[]

Config property description

Property NameDescriptionDefault Value
configIt is an object it contains the sideMenu, these will be used to configure the canvas{ traceId: "12345", sideMenu: {"showShare": true, "showDownload": true, "showReplay": true, "showExit": true}}
config.traceIdIt is string which defines the trace id''
config.sideMenu.showShareIt is boolean to show/hide share button in side menutrue
config.sideMenu.showDownloadIt is boolean to show/hide download button in side menutrue
config.sideMenu.showReplayIt is boolean to show/hide replay button in side menutrue
config.sideMenu.showExitIt is boolean to show/hide exit button in side menutrue
config.transcriptsIt is Array which defines the transcripts default selection details[]
metadataIt is an object which defines content metadata json object (from API response take -> response.result.content){}
metadata.transcriptsIt is Array which is having the details of the transcripts data[]

Available components

FeatureNotesSelectorCodeInputOutput
Video PlayerCan be used to render videossunbird-video-player<sunbird-video-player [playerConfig]="playerConfig"><sunbird-video-player>playerConfig,actionplayerEvent, telemetryEvent

Use as Web component in Mobile app

For existing apps, follow these steps steps to begin using.

Use as Angular library in Mobile app

For existing apps, follow these steps to begin using.

Step 1: Install the packages

Click to see the steps - InstallPackages

Step 2: Include the sb-styles and assets in angular.json

Click to see the steps - IncludeStyles , but use src/global.scss instead of src/styles.css in styles.

Step 3: Import the modules and components

Click to see the steps - Import

Step 4: Import in component

 <sunbird-video-player [playerConfig]="playerConfig" (playerEvent)="playerEvents($event)"
  (telemetryEvent)="playerTelemetryEvents($event)"></sunbird-video-player> 

Note : An additional property named action can be added to the above statement to implement pause and play functionality for the video player.

Step 5: Send input to render VIDEO player

Click to see the input data - playerConfig

Sample code

Click to see the sample code - sampleCode

6.1.0

1 month ago

6.1.1

1 month ago

6.1.1-alpha.0

1 month ago

6.1.0-alpha.1

2 months ago

6.1.0-alpha.0

2 months ago

6.0.1

5 months ago

6.0.0

6 months ago

5.5.1

1 year ago

5.4.5

1 year ago

5.4.4

1 year ago

5.4.3

1 year ago

5.4.2

1 year ago

5.4.1

1 year ago

5.3.2

1 year ago

5.1.3

1 year ago

5.1.2

1 year ago

5.2.4

1 year ago

5.4.0

1 year ago

5.3.1

1 year ago

5.3.0

1 year ago

5.2.3

1 year ago

5.2.2

2 years ago

5.2.1

2 years ago

5.2.0

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.10.1

2 years ago

4.10.2

2 years ago

4.10.0

2 years ago

4.8.0

2 years ago

4.7.1

2 years ago

4.6.3

2 years ago

4.6.5

2 years ago

4.6.4

2 years ago

4.6.2

2 years ago

4.7.0

2 years ago

4.6.1

2 years ago

4.5.0

2 years ago

4.4.1

2 years ago

4.6.0

2 years ago

4.4.2

2 years ago

4.4.0

3 years ago

4.3.0

3 years ago

4.1.10

3 years ago

4.2.6

3 years ago

4.1.9

3 years ago

4.1.8

3 years ago

4.2.3

3 years ago

4.2.5

3 years ago

4.2.4

3 years ago

4.2.2

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.7

3 years ago

4.1.4

3 years ago

4.1.3

3 years ago

4.1.6

3 years ago

4.1.5

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.1.0

3 years ago