5353 * @param {number } [options.interval=0.1] 非定点视频参数间隔,单位秒,当视频参数为数组时,会根据该参数将 VideoTimeParameters.time 处理成均匀间隔的视频参数,默认为 0.1 秒,最小值为 0.001 秒。
5454 * @param {string } [options.id] - 视频图层 ID。默认使用 CommonUtil.createUniqueID("VideoLayer_") 创建专题图层 ID。
5555 * @param {Array } [options.clipRegion] -裁剪范围
56+ * @fires VideoLayer#play
57+ * @fires VideoLayer#pause
5658 * @extends {mapboxgl.Evented }
5759 * @usage
5860 * ```
116118 this . renderer = new VideoLayerRenderer ( { url : this . url , id : this . layerId } ) ;
117119 this . video = this . renderer . createVideo ( ) ;
118120 this . videoDomId = this . renderer . getVideoDomId ( ) ;
121+ this . _bindPlaybackEvents ( ) ;
119122
120123 this . video . one ( 'firstplay' , ( ) => {
121124 this . video . play ( ) ;
516519 const visible = visibility ? 'visible' : 'none' ;
517520 this . map . setLayoutProperty ( this . layerId , 'visibility' , visible ) ;
518521 }
522+
523+ /**
524+ * @function VideoLayer.prototype.play
525+ * @description 播放视频。
526+ */
527+ play ( ) {
528+ if ( this . video ) {
529+ this . video . play ( ) ;
530+ }
531+ const source = this . _getVideoSource ( ) ;
532+ if ( source && typeof source . play === 'function' ) {
533+ source . play ( ) ;
534+ }
535+ }
536+
537+ /**
538+ * @function VideoLayer.prototype.pause
539+ * @description 暂停视频。
540+ */
541+ pause ( ) {
542+ if ( this . video ) {
543+ this . video . pause ( ) ;
544+ }
545+ const source = this . _getVideoSource ( ) ;
546+ if ( source && typeof source . pause === 'function' ) {
547+ source . pause ( ) ;
548+ }
549+ }
550+
551+ /**
552+ * @function VideoLayer.prototype.paused
553+ * @description 获取当前视频播放状态。返回 `true` 表示已暂停,返回 `false` 表示正在播放。
554+ * @returns {boolean } 视频是否暂停。
555+ */
556+ paused ( ) {
557+ if ( this . video && typeof this . video . paused === 'function' ) {
558+ return this . video . paused ( ) ;
559+ }
560+ return true ;
561+ }
562+
563+ _bindPlaybackEvents ( ) {
564+ if ( ! this . video ) {
565+ return ;
566+ }
567+ /**
568+ * @event VideoLayer#play
569+ * @description 视频开始播放时触发。
570+ */
571+ this . video . on ( 'play' , ( ) => {
572+ this . fire ( 'play' ) ;
573+ } ) ;
574+ /**
575+ * @event VideoLayer#pause
576+ * @description 视频暂停时触发。
577+ */
578+ this . video . on ( 'pause' , ( ) => {
579+ this . fire ( 'pause' ) ;
580+ } ) ;
581+ }
582+
583+ _getVideoSource ( ) {
584+ if ( ! this . map || ! this . layerId || typeof this . map . getSource !== 'function' ) {
585+ return null ;
586+ }
587+ return this . map . getSource ( this . layerId ) || null ;
588+ }
519589 }
520590
0 commit comments