<script src="https://cloudcache.tencentcs.com/qcloud/video/dist/tcadapter.1.0.0.min.js"></script>
// npm installnpm install tcadapter --save// import TcAdapterimport TcAdapter from 'tcadapter';
<video id="player-container-id"></video>
TcAdapter.isSupported();
const adapter = new TcAdapter('player-container-id', {fileID: string,appID: string,psign: string,hlsConfig: {}}, callback);
Parameter | Type | Description |
appID | String | The APPID of the VOD account. |
fileID | String | The fileId of the video to be played back. |
psign | String | The player signature. |
hlsConfig | HlsConfig | HLS settings. Any parameters supported by hls.js can be used. |
callback | TcAdapterCallBack | Callback for initialization completion. Basic video information can be obtained after this method is used. |
hls.js
, and it can receive any parameters supported by hls.js
through HlsConfig
to fine-tune playback.VideoBasicInfo adapter.getVideoBasicInfo();
VideoBasicInfo
are as follows:Parameter | Type | Description |
name | String | The video name. |
duration | Float | Video duration in seconds. |
description | String | The video description. |
coverUrl | String | The video thumbnail. |
List<StreamingOutput> adapter.getStreamimgOutputList();
StreamingOutput
are as follows:Parameter | Type | Description |
drmType | String | The adaptive bitstream protection type. Valid values: plain (no encryption), simpleAES (HLS common encryption). |
playUrl | String | Playback URL |
subStreams | List |
SubStreamInfo
are as follows:Parameter | Type | Description |
type | String | Substream type. Valid values: video |
width | Int | The substream video width in px. |
height | Int | The substream video height in px. |
resolutionName | String | The name of the substream video displayed in the player. |
List<KeyFrameDescInfo> adapter.getKeyFrameDescInfo();
KeyFrameDescInfo
are as follows:Parameter | Type | Description |
timeOffset | Float | 1.1 |
content | String | "Beginning now..." |
ImageSpriteInfo adapter.getImageSpriteInfo();
ImageSpriteInfo
are as follows:Parameter | Type | Description |
imageUrls | List | Array of thumbnail download URLs of String type. |
webVttUrl | String | Thumbnail VTT file download URL. |
const adapter = TcAdapter('player-container-id', options);adapter.on(TcAdapter.TcAdapterEvents.Error, function(error) {// do something});
type
is the event type. Supported events include HLS' native events and the following events. Event names can be accessed from TcAdapter.TcAdapterEvents
:Name | Description |
LOADEDMETADATA | The corresponding video information was obtained through playcgi . Relevant video information can be obtained through this event callback. |
HLSREADY | An HLS instance was created. At this point, you can call the various attributes and methods of the HLS instance object. |
ERROR | This event will be triggered when an error occurs. You can view the specific failure cause according to the callback parameters. |
adapter.on('hlsready', () => {const hls = adapter.hls;// ...})
import { useEffect, useRef } from 'react';import TcAdapter from 'tcadapter';function App() {if (!TcAdapter.isSupported()) {throw new Error('current environment can not support TcAdapter');}const videoRef = useRef(null);useEffect(() => {const adapter = new TcAdapter(videoRef.current, {appID: '1500002611',fileID: '5285890813738446783',psign: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTUwMDAwMjYxMSwiZmlsZUlkIjoiNTI4NTg5MDgxMzczODQ0Njc4MyIsImN1cnJlbnRUaW1lU3RhbXAiOjE2MTU5NTEyMzksImV4cGlyZVRpbWVTdGFtcCI6MjIxNTY1MzYyMywicGNmZyI6ImJhc2ljRHJtUHJlc2V0IiwidXJsQWNjZXNzSW5mbyI6eyJ0IjoiMjIxNTY1MzYyMyJ9fQ.hRrQYvC0UYtcO-ozB35k7LZI6E3ruvow7DC0XzzdYKE',hlsConfig: {},}, () => {console.log('basicInfo', adapter.getVideoBasicInfo());});adapter.on(TcAdapter.TcAdapterEvents.HLSREADY, () => {const hls = adapter.hls;// ...})}, []);const play = () => {videoRef.current.play();}return (<div><div><video id="player" ref={ videoRef }></video></div><button onClick={play}>play</button></div>);}export default App;
// 1. Video.js playback over HLS uses `@videojs/http-streaming`, so we have developed a set of policies for playback with TcAdapter to override the original logic (you can also directly modify the internal logic of `@videojs/http-streaming`)// src/js/index.jsimport videojs from './video';import '@videojs/http-streaming';import './tech/tcadapter'; // Add logicexport default videojs;// src/js/tech/tcadapter.jsimport videojs from '../video.js';import TcAdapter from 'tcadapter';class Adapter {constructor(source, tech, options) {const el = tech.el();// Get parameters and initialize the instanceconst adapter = new TcAdapter(el, {appID: '1500002611',fileID: '5285890813738446783',psign: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTUwMDAwMjYxMSwiZmlsZUlkIjoiNTI4NTg5MDgxMzczODQ0Njc4MyIsImN1cnJlbnRUaW1lU3RhbXAiOjE2MTU5NTEyMzksImV4cGlyZVRpbWVTdGFtcCI6MjIxNTY1MzYyMywicGNmZyI6ImJhc2ljRHJtUHJlc2V0IiwidXJsQWNjZXNzSW5mbyI6eyJ0IjoiMjIxNTY1MzYyMyJ9fQ.hRrQYvC0UYtcO-ozB35k7LZI6E3ruvow7DC0XzzdYKE',hlsConfig: {},});adapter.on(TcAdapter.TcAdapterEvents.LEVEL_LOADED, this.onLevelLoaded.bind(this));}dispose() {this.hls.destroy();}onLevelLoaded(event) {this._duration = event.data.details.live ? Infinity : event.data.details.totalduration;}}let hlsTypeRE = /^application\\/(x-mpegURL|vnd\\.apple\\.mpegURL)$/i;let hlsExtRE = /\\.m3u8/i;let HlsSourceHandler = {name: 'hlsSourceHandler',canHandleSource: function (source) {// skip hls fairplay, need to use Safari resolve it.if (source.skipHlsJs || (source.keySystems && source.keySystems['com.apple.fps.1_0'])) {return '';} else if (hlsTypeRE.test(source.type)) {return 'probably';} else if (hlsExtRE.test(source.src)) {return 'maybe';} else {return '';}},handleSource: function (source, tech, options) {if (tech.hlsProvider) {tech.hlsProvider.dispose();tech.hlsProvider = null;} else {// After automatic loading is disabled for HLS, you need to manually load resourcesif (options.hlsConfig && options.hlsConfig.autoStartLoad === false) {tech.on('play', function () {if (!this.player().hasStarted()) {this.hlsProvider.hls.startLoad();}});}}tech.hlsProvider = new Adapter(source, tech, options);return tech.hlsProvider;},canPlayType: function (type) {if (hlsTypeRE.test(type)) {return 'probably';}return '';}};function mountHlsProvider(enforce) {if (TcAdapter && TcAdapter.isSupported() || !!enforce) {try {let html5Tech = videojs.getTech && videojs.getTech('Html5');if (html5Tech) {html5Tech.registerSourceHandler(HlsSourceHandler, 0);}} catch (e) {console.error('hls.js init failed');}} else {// TcAdapter is not imported, MSE is not available, or X5 kernel is disabled}}mountHlsProvider();export default Adapter;
Was this page helpful?