import * as aribb24js from 'aribb24.js' ; import Hls from 'hls.js' ; import { injectable } from 'inversify' ; import HLSUtil from '../../../../util/HLSUtil' ; import IB24RenderState from './IB24RenderState' ; @ injectable ( ) export default class B24RenderState implements IB24RenderState { private b24Renderer : aribb24js . CanvasRenderer | null = null ; param video param hls public init ( video , hls ? ) { this . destroy ( ) ; const b24Option = HLSUtil . getAribb24BaseOption ( ) ; this . b24Renderer = new aribb24js . CanvasRenderer ( b24Option ) ; this . b24Renderer . attachMedia ( video ) ; if ( typeof hls !== 'undefined' ) { hls . on ( Hls . Events . FRAG_PARSING_METADATA , ( _e , data ) => { for ( const sample of data . samples ) { this . b24Renderer ?. pushID3v2Data ( sample . pts , sample . data ) ; } } ) ; } } /**
     * destory b24 subtitle render
     */ public destroy ( ) { if ( this . b24Renderer === null ) { return ; } this . b24Renderer . detachMedia ( ) ; this . b24Renderer . dispose ( ) ; this . b24Renderer = null ; } return public isInited ( ) { return this . b24Renderer !== null ; } /**
     * 字幕を表示させる
     */ public showSubtitle ( ) { if ( this . b24Renderer !== null ) { this . b24Renderer . show ( ) ; } } /**
     * 字幕を非表示にする
     */ public disabledSubtitle ( ) { if ( this . b24Renderer !== null ) { this . b24Renderer . hide ( ) ; } } }