@jxstjh/jhvideo
Version:
HTML5 jhvideo base on MPEG2-TS Stream Player
717 lines • 30.3 kB
JavaScript
/*
* Copyright (C) 2016 Bilibili. All Rights Reserved.
*
* @author zheng qian <xqq@xqq.im>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import EventEmitter from 'events';
import Log from '../utils/logger.js';
import Browser from '../utils/browser.js';
import PlayerEvents from './player-events.js';
import Transmuxer from '../core/transmuxer.js';
import TransmuxingEvents from '../core/transmuxing-events.js';
import MSEController from '../core/mse-controller.js';
import MSEEvents from '../core/mse-events.js';
import { ErrorTypes, ErrorDetails } from './player-errors.js';
import { createDefaultConfig } from '../config.js';
import { InvalidArgumentException, IllegalStateException } from '../utils/exception.js';
import { Player as WasmPlayer, EventInfo } from './wasm_player.js';
var MSEPlayer = /** @class */ (function () {
function MSEPlayer(mediaDataSource, config) {
this.TAG = 'MSEPlayer';
this._type = 'MSEPlayer';
this._wasmPlayer = null;
this._emitter = new EventEmitter();
this._config = createDefaultConfig();
if (typeof config === 'object') {
Object.assign(this._config, config);
}
var typeLowerCase = mediaDataSource.type.toLowerCase();
if (typeLowerCase !== 'mse'
&& typeLowerCase !== 'mpegts'
&& typeLowerCase !== 'm2ts'
&& typeLowerCase !== 'flv') {
throw new InvalidArgumentException('MSEPlayer requires an mpegts/m2ts/flv MediaDataSource input!');
}
if (mediaDataSource.isLive === true) {
this._config.isLive = true;
}
this.e = {
onvLoadedMetadata: this._onvLoadedMetadata.bind(this),
onvSeeking: this._onvSeeking.bind(this),
onvCanPlay: this._onvCanPlay.bind(this),
onvStalled: this._onvStalled.bind(this),
onvProgress: this._onvProgress.bind(this),
};
if (self.performance && self.performance.now) {
this._now = self.performance.now.bind(self.performance);
}
else {
this._now = Date.now;
}
this._pendingSeekTime = null; // in seconds
this._requestSetTime = false;
this._seekpointRecord = null;
this._progressChecker = null;
this._mediaDataSource = mediaDataSource;
this._mediaElement = null;
this._canvasElement = null;
this._msectl = null;
this._transmuxer = null;
this._mseSourceOpened = false;
this._hasPendingLoad = false;
this._receivedCanPlay = false;
this._mediaInfo = null;
this._statisticsInfo = null;
var chromeNeedIDRFix = (Browser.chrome &&
(Browser.version.major < 50 ||
(Browser.version.major === 50 && Browser.version.build < 2661)));
this._alwaysSeekKeyframe = (chromeNeedIDRFix || Browser.msedge || Browser.msie) ? true : false;
if (this._alwaysSeekKeyframe) {
this._config.accurateSeek = false;
}
}
MSEPlayer.prototype.destroy = function () {
if (this._progressChecker != null) {
window.clearInterval(this._progressChecker);
this._progressChecker = null;
}
if (this._transmuxer) {
this.unload();
}
if (this._mediaElement || this._canvasElement) {
this.detachMediaElement();
}
if (this._wasmPlayer) {
this._wasmPlayer.destroy();
}
this.e = null;
this._mediaDataSource = null;
this._emitter.removeAllListeners();
this._emitter = null;
};
MSEPlayer.prototype.on = function (event, listener) {
var _this = this;
if (event === PlayerEvents.MEDIA_INFO) {
if (this._mediaInfo != null) {
Promise.resolve().then(function () {
_this._emitter.emit(PlayerEvents.MEDIA_INFO, _this.mediaInfo);
});
}
}
else if (event === PlayerEvents.STATISTICS_INFO) {
if (this._statisticsInfo != null) {
Promise.resolve().then(function () {
_this._emitter.emit(PlayerEvents.STATISTICS_INFO, _this.statisticsInfo);
});
}
}
this._emitter.addListener(event, listener);
};
MSEPlayer.prototype.off = function (event, listener) {
this._emitter.removeListener(event, listener);
};
MSEPlayer.prototype.attachMediaElement = function (mediaElement, canvasElement) {
var _this = this;
this._mediaElement = mediaElement;
this._canvasElement = canvasElement;
mediaElement.addEventListener('loadedmetadata', this.e.onvLoadedMetadata);
mediaElement.addEventListener('seeking', this.e.onvSeeking);
mediaElement.addEventListener('canplay', this.e.onvCanPlay);
mediaElement.addEventListener('stalled', this.e.onvStalled);
mediaElement.addEventListener('progress', this.e.onvProgress);
this._msectl = new MSEController(this._config);
this._msectl.on(MSEEvents.UPDATE_END, this._onmseUpdateEnd.bind(this));
this._msectl.on(MSEEvents.BUFFER_FULL, this._onmseBufferFull.bind(this));
this._msectl.on(MSEEvents.SOURCE_OPEN, function () {
_this._mseSourceOpened = true;
if (_this._hasPendingLoad) {
_this._hasPendingLoad = false;
_this.load();
}
});
this._msectl.on(MSEEvents.SOURCE_CLOSE, this._onmseSourceClose.bind(this));
this._msectl.on(MSEEvents.SOURCE_ENDED, this._onmseSourceEnded.bind(this));
this._msectl.on(MSEEvents.ERROR, function (info) {
_this._emitter.emit(PlayerEvents.ERROR, ErrorTypes.MEDIA_ERROR, ErrorDetails.MEDIA_MSE_ERROR, info);
});
this._msectl.attachMediaElement(mediaElement);
if (this._pendingSeekTime != null) {
try {
mediaElement.currentTime = this._pendingSeekTime;
this._pendingSeekTime = null;
}
catch (e) {
// IE11 may throw InvalidStateError if readyState === 0
// We can defer set currentTime operation after loadedmetadata
}
}
};
MSEPlayer.prototype.detachMediaElement = function () {
if (this._mediaElement) {
this._msectl.detachMediaElement();
this._mediaElement.removeEventListener('loadedmetadata', this.e.onvLoadedMetadata);
this._mediaElement.removeEventListener('seeking', this.e.onvSeeking);
this._mediaElement.removeEventListener('canplay', this.e.onvCanPlay);
this._mediaElement.removeEventListener('stalled', this.e.onvStalled);
this._mediaElement.removeEventListener('progress', this.e.onvProgress);
this._mediaElement = null;
}
if (this._canvasElement) {
this._canvasElement = null;
}
if (this._msectl) {
this._msectl.destroy();
this._msectl = null;
}
};
MSEPlayer.prototype.load = function () {
var _this = this;
if (!this._mediaElement) {
throw new IllegalStateException('HTMLMediaElement must be attached before load()!');
}
if (this._transmuxer) {
throw new IllegalStateException('MSEPlayer.load() has been called, please call unload() first!');
}
if (this._hasPendingLoad) {
return;
}
if (this._config.deferLoadAfterSourceOpen && this._mseSourceOpened === false) {
this._hasPendingLoad = true;
return;
}
if (this._mediaElement.readyState > 0) {
this._requestSetTime = true;
// IE11 may throw InvalidStateError if readyState === 0
this._mediaElement.currentTime = 0;
}
this._transmuxer = new Transmuxer(this._mediaDataSource, this._config);
this._transmuxer.on(TransmuxingEvents.INIT_SEGMENT, function (type, is) {
_this._msectl.appendInitSegment(is);
});
this._transmuxer.on(TransmuxingEvents.MEDIA_SEGMENT, function (type, ms) {
_this._msectl.appendMediaSegment(ms);
// lazyLoad check
if (_this._config.lazyLoad && !_this._config.isLive) {
var currentTime = _this._mediaElement.currentTime;
if (ms.info.endDts >= (currentTime + _this._config.lazyLoadMaxDuration) * 1000) {
if (_this._progressChecker == null) {
Log.v(_this.TAG, 'Maximum buffering duration exceeded, suspend transmuxing task');
_this._suspendTransmuxer();
}
}
}
});
this._transmuxer.on(TransmuxingEvents.LOADING_COMPLETE, function () {
_this._msectl.endOfStream();
_this._emitter.emit(PlayerEvents.LOADING_COMPLETE);
});
this._transmuxer.on(TransmuxingEvents.RECOVERED_EARLY_EOF, function () {
_this._emitter.emit(PlayerEvents.RECOVERED_EARLY_EOF);
});
this._transmuxer.on(TransmuxingEvents.IO_ERROR, function (detail, info) {
_this._emitter.emit(PlayerEvents.ERROR, ErrorTypes.NETWORK_ERROR, detail, info);
});
this._transmuxer.on(TransmuxingEvents.DEMUX_ERROR, function (detail, info) {
_this._emitter.emit(PlayerEvents.ERROR, ErrorTypes.MEDIA_ERROR, detail, { code: -1, msg: info });
});
this._transmuxer.on(TransmuxingEvents.MEDIA_INFO, function (mediaInfo) {
_this._mediaInfo = mediaInfo;
_this._emitter.emit(PlayerEvents.MEDIA_INFO, Object.assign({}, mediaInfo));
});
this._transmuxer.on(TransmuxingEvents.METADATA_ARRIVED, function (metadata) {
_this._emitter.emit(PlayerEvents.METADATA_ARRIVED, metadata);
});
// 自定义返回JSON信息
this._transmuxer.on(TransmuxingEvents.JSON_INFORMATION, function (detail, info) {
_this._emitter.emit(PlayerEvents.JSON_INFORMATION, detail, info);
});
this._transmuxer.on(TransmuxingEvents.SCRIPTDATA_ARRIVED, function (data) {
_this._emitter.emit(PlayerEvents.SCRIPTDATA_ARRIVED, data);
});
this._transmuxer.on(TransmuxingEvents.PES_PRIVATE_DATA_DESCRIPTOR, function (descriptor) {
_this._emitter.emit(PlayerEvents.PES_PRIVATE_DATA_DESCRIPTOR, descriptor);
});
this._transmuxer.on(TransmuxingEvents.PES_PRIVATE_DATA_ARRIVED, function (private_data) {
_this._emitter.emit(PlayerEvents.PES_PRIVATE_DATA_ARRIVED, private_data);
});
this._transmuxer.on(TransmuxingEvents.STATISTICS_INFO, function (statInfo) {
_this._statisticsInfo = _this._fillStatisticsInfo(statInfo);
_this._emitter.emit(PlayerEvents.STATISTICS_INFO, Object.assign({}, _this._statisticsInfo));
});
this._transmuxer.on(TransmuxingEvents.RECOMMEND_SEEKPOINT, function (milliseconds) {
if (_this._mediaElement && !_this._config.accurateSeek) {
_this._requestSetTime = true;
_this._mediaElement.currentTime = milliseconds / 1000;
}
});
this._transmuxer.on(TransmuxingEvents.ESDATA_ARRIVED, function (type, data) {
if (!_this._wasmPlayer) {
_this._createWasmPlayer(data.codecId, data.duration);
}
else {
_this._wasmPlayer.inputData(type, data);
}
});
this._transmuxer.on(TransmuxingEvents.ESSCRIPTDATA_ARRIVED, function (data) {
if (!_this._wasmPlayer) {
_this._createWasmPlayer(data.codecId);
}
});
this._transmuxer.open();
};
MSEPlayer.prototype.unload = function () {
if (this._mediaElement) {
this._mediaElement.pause();
}
if (this._msectl) {
this._msectl.seek(0);
}
if (this._transmuxer) {
this._transmuxer.close();
this._transmuxer.destroy();
this._transmuxer = null;
}
};
MSEPlayer.prototype.play = function () {
if (this._wasmPlayer) {
return this._wasmPlayer.play();
}
else {
return this._mediaElement.play();
}
};
MSEPlayer.prototype.pause = function () {
if (this._wasmPlayer) {
this._wasmPlayer.pause();
}
else {
this._mediaElement.pause();
}
};
MSEPlayer.prototype.inputData = function (chunk) {
if (!this._config.useOuterLoader) {
return new Error('Not set useOuterLoader config.');
}
if (this._receivedLength === undefined) {
this._receivedLength = 0;
}
var byteStart = this._receivedLength;
this._receivedLength += chunk.byteLength;
// return this._transmuxer._controller._ioctl._onLoaderChunkArrival(chunk, byteStart, this._receivedLength);
if (this._transmuxer && this._transmuxer.inputData) {
return this._transmuxer.inputData(chunk, byteStart, this._receivedLength);
}
};
Object.defineProperty(MSEPlayer.prototype, "type", {
get: function () {
return this._type;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MSEPlayer.prototype, "buffered", {
get: function () {
return this._mediaElement.buffered;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MSEPlayer.prototype, "duration", {
get: function () {
return this._mediaElement.duration;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MSEPlayer.prototype, "volume", {
get: function () {
return this._mediaElement.volume;
},
set: function (value) {
this._mediaElement.volume = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MSEPlayer.prototype, "muted", {
get: function () {
return this._mediaElement.muted;
},
set: function (muted) {
this._mediaElement.muted = muted;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MSEPlayer.prototype, "currentTime", {
get: function () {
if (this._mediaElement) {
return this._mediaElement.currentTime;
}
return 0;
},
set: function (seconds) {
if (this._mediaElement) {
this._internalSeek(seconds);
}
else {
this._pendingSeekTime = seconds;
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(MSEPlayer.prototype, "mediaInfo", {
get: function () {
if (!!this._wasmPlayer) {
return Object.assign({}, this._wasmPlayer.mediaInfo);
}
return Object.assign({}, this._mediaInfo);
},
enumerable: false,
configurable: true
});
Object.defineProperty(MSEPlayer.prototype, "statisticsInfo", {
get: function () {
if (this._statisticsInfo == null) {
this._statisticsInfo = {};
}
this._statisticsInfo = this._fillStatisticsInfo(this._statisticsInfo);
return Object.assign({}, this._statisticsInfo);
},
enumerable: false,
configurable: true
});
MSEPlayer.prototype._fillStatisticsInfo = function (statInfo) {
statInfo.playerType = this._type;
if (!(this._mediaElement instanceof HTMLVideoElement)) {
return statInfo;
}
var hasQualityInfo = true;
var decoded = 0;
var dropped = 0;
if (this._mediaElement.getVideoPlaybackQuality) {
var quality = this._mediaElement.getVideoPlaybackQuality();
decoded = quality.totalVideoFrames;
dropped = quality.droppedVideoFrames;
}
else if (this._mediaElement.webkitDecodedFrameCount != undefined) {
decoded = this._mediaElement.webkitDecodedFrameCount;
dropped = this._mediaElement.webkitDroppedFrameCount;
}
else {
hasQualityInfo = false;
}
if (hasQualityInfo) {
statInfo.decodedFrames = decoded;
statInfo.droppedFrames = dropped;
}
return statInfo;
};
MSEPlayer.prototype._onmseUpdateEnd = function () {
var buffered = this._mediaElement.buffered;
var currentTime = this._mediaElement.currentTime;
if (this._config.isLive
&& this._config.liveBufferLatencyChasing
&& buffered.length > 0
&& !this._mediaElement.paused) {
var buffered_end = buffered.end(buffered.length - 1);
if (buffered_end > this._config.liveBufferLatencyMaxLatency) {
// Ensure there's enough buffered data
if (buffered_end - currentTime > this._config.liveBufferLatencyMaxLatency) {
// if remained data duration has larger than config.liveBufferLatencyMaxLatency
var target_time = buffered_end - this._config.liveBufferLatencyMinRemain;
this.currentTime = target_time;
}
}
}
if (!this._config.lazyLoad || this._config.isLive) {
return;
}
var currentRangeStart = 0;
var currentRangeEnd = 0;
for (var i = 0; i < buffered.length; i++) {
var start = buffered.start(i);
var end = buffered.end(i);
if (start <= currentTime && currentTime < end) {
currentRangeStart = start;
currentRangeEnd = end;
break;
}
}
if (currentRangeEnd >= currentTime + this._config.lazyLoadMaxDuration && this._progressChecker == null) {
Log.v(this.TAG, 'Maximum buffering duration exceeded, suspend transmuxing task');
this._suspendTransmuxer();
}
};
MSEPlayer.prototype._onmseBufferFull = function () {
Log.v(this.TAG, 'MSE SourceBuffer is full, suspend transmuxing task');
if (this._progressChecker == null) {
this._suspendTransmuxer();
}
};
MSEPlayer.prototype._onmseSourceEnded = function () {
this._emitter.emit(PlayerEvents.ERROR, ErrorTypes.MEDIA_ERROR, ErrorDetails.MEDIA_MSE_ERROR, 'mseSourceEnded');
};
MSEPlayer.prototype._onmseSourceClose = function () {
this._emitter.emit(PlayerEvents.ERROR, ErrorTypes.MEDIA_ERROR, ErrorDetails.MEDIA_MSE_ERROR, 'mseSourceClose');
};
MSEPlayer.prototype._suspendTransmuxer = function () {
if (this._transmuxer) {
this._transmuxer.pause();
if (this._progressChecker == null) {
this._progressChecker = window.setInterval(this._checkProgressAndResume.bind(this), 1000);
}
}
};
MSEPlayer.prototype._checkProgressAndResume = function () {
var currentTime = this._mediaElement.currentTime;
var buffered = this._mediaElement.buffered;
var needResume = false;
for (var i = 0; i < buffered.length; i++) {
var from = buffered.start(i);
var to = buffered.end(i);
if (currentTime >= from && currentTime < to) {
if (currentTime >= to - this._config.lazyLoadRecoverDuration) {
needResume = true;
}
break;
}
}
if (needResume) {
window.clearInterval(this._progressChecker);
this._progressChecker = null;
if (needResume) {
Log.v(this.TAG, 'Continue loading from paused position');
this._transmuxer.resume();
}
}
};
MSEPlayer.prototype._isTimepointBuffered = function (seconds) {
var buffered = this._mediaElement.buffered;
for (var i = 0; i < buffered.length; i++) {
var from = buffered.start(i);
var to = buffered.end(i);
if (seconds >= from && seconds < to) {
return true;
}
}
return false;
};
MSEPlayer.prototype._internalSeek = function (seconds) {
var directSeek = this._isTimepointBuffered(seconds);
var directSeekBegin = false;
var directSeekBeginTime = 0;
if (seconds < 1.0 && this._mediaElement.buffered.length > 0) {
var videoBeginTime = this._mediaElement.buffered.start(0);
if ((videoBeginTime < 1.0 && seconds < videoBeginTime) || Browser.safari) {
directSeekBegin = true;
// also workaround for Safari: Seek to 0 may cause video stuck, use 0.1 to avoid
directSeekBeginTime = Browser.safari ? 0.1 : videoBeginTime;
}
}
if (directSeekBegin) { // seek to video begin, set currentTime directly if beginPTS buffered
this._requestSetTime = true;
this._mediaElement.currentTime = directSeekBeginTime;
}
else if (directSeek) { // buffered position
if (!this._alwaysSeekKeyframe) {
this._requestSetTime = true;
this._mediaElement.currentTime = seconds;
this._emitter.emit('onClientSeeked', seconds);
}
else {
var idr = this._msectl.getNearestKeyframe(Math.floor(seconds * 1000));
this._requestSetTime = true;
if (idr != null) {
this._mediaElement.currentTime = idr.dts / 1000;
this._emitter.emit('onClientSeeked', idr.dts / 1000);
}
else {
this._mediaElement.currentTime = seconds;
this._emitter.emit('onClientSeeked', seconds);
}
}
if (this._progressChecker != null) {
this._checkProgressAndResume();
}
}
else {
console.log('!_beginOriginSeek');
this._beginOriginSeek(seconds);
// if (this._progressChecker != null) {
// window.clearInterval(this._progressChecker);
// this._progressChecker = null;
// }
// this._msectl.seek(seconds);
// this._transmuxer.seek(Math.floor(seconds * 1000)); // in milliseconds
// // no need to set mediaElement.currentTime if non-accurateSeek,
// // just wait for the recommend_seekpoint callback
// if (this._config.accurateSeek) {
// this._requestSetTime = true;
// this._mediaElement.currentTime = seconds;
// }
}
};
MSEPlayer.prototype._beginOriginSeek = function (seconds) {
this._emitter.emit('onOriginSeekStart', seconds);
};
MSEPlayer.prototype._originSeekSuccess = function (seconds) {
// if (this._progressChecker != null) {
// window.clearInterval(this._progressChecker);
// this._progressChecker = null;
// }
this._msectl.seek(seconds);
this._transmuxer.seek(Math.floor(seconds * 1000)); // in milliseconds
// no need to set mediaElement.currentTime if non-accurateSeek,
// just wait for the recommend_seekpoint callback
if (!this._config.accurateSeek) {
this._requestSetTime = true;
this._mediaElement.currentTime = seconds;
}
};
MSEPlayer.prototype._checkAndApplyUnbufferedSeekpoint = function () {
if (this._seekpointRecord) {
if (this._seekpointRecord.recordTime <= this._now() - 100) {
var target = this._mediaElement.currentTime;
this._seekpointRecord = null;
if (!this._isTimepointBuffered(target)) {
if (this._progressChecker != null) {
window.clearTimeout(this._progressChecker);
this._progressChecker = null;
}
// .currentTime is consists with .buffered timestamp
// Chrome/Edge use DTS, while FireFox/Safari use PTS
this._msectl.seek(target);
this._transmuxer.seek(Math.floor(target * 1000));
// set currentTime if accurateSeek, or wait for recommend_seekpoint callback
if (this._config.accurateSeek) {
this._requestSetTime = true;
this._mediaElement.currentTime = target;
}
}
}
else {
window.setTimeout(this._checkAndApplyUnbufferedSeekpoint.bind(this), 50);
}
}
};
MSEPlayer.prototype._checkAndResumeStuckPlayback = function (stalled) {
var media = this._mediaElement;
if (stalled || !this._receivedCanPlay || media.readyState < 2) { // HAVE_CURRENT_DATA
var buffered = media.buffered;
if (buffered.length > 0 && media.currentTime < buffered.start(0)) {
Log.w(this.TAG, "Playback seems stuck at ".concat(media.currentTime, ", seek to ").concat(buffered.start(0)));
this._requestSetTime = true;
this._mediaElement.currentTime = buffered.start(0);
this._mediaElement.removeEventListener('progress', this.e.onvProgress);
}
}
else {
// Playback didn't stuck, remove progress event listener
this._mediaElement.removeEventListener('progress', this.e.onvProgress);
}
};
MSEPlayer.prototype._onvLoadedMetadata = function (e) {
if (this._pendingSeekTime != null) {
this._mediaElement.currentTime = this._pendingSeekTime;
this._pendingSeekTime = null;
}
};
MSEPlayer.prototype._onvSeeking = function (e) {
var target = this._mediaElement.currentTime;
var buffered = this._mediaElement.buffered;
if (this._requestSetTime) {
this._requestSetTime = false;
return;
}
if (target < 1.0 && buffered.length > 0) {
// seek to video begin, set currentTime directly if beginPTS buffered
var videoBeginTime = buffered.start(0);
if ((videoBeginTime < 1.0 && target < videoBeginTime) || Browser.safari) {
this._requestSetTime = true;
// also workaround for Safari: Seek to 0 may cause video stuck, use 0.1 to avoid
this._mediaElement.currentTime = Browser.safari ? 0.1 : videoBeginTime;
return;
}
}
if (this._isTimepointBuffered(target)) {
if (this._alwaysSeekKeyframe) {
var idr = this._msectl.getNearestKeyframe(Math.floor(target * 1000));
if (idr != null) {
this._requestSetTime = true;
this._mediaElement.currentTime = idr.dts / 1000;
}
}
if (this._progressChecker != null) {
this._checkProgressAndResume();
}
return;
}
this._seekpointRecord = {
seekPoint: target,
recordTime: this._now()
};
window.setTimeout(this._checkAndApplyUnbufferedSeekpoint.bind(this), 50);
};
MSEPlayer.prototype._onvCanPlay = function (e, t) {
this._emitter.emit('onVCanPlay');
this._receivedCanPlay = true;
this._mediaElement.removeEventListener('canplay', this.e.onvCanPlay);
};
MSEPlayer.prototype._onvStalled = function (e) {
this._checkAndResumeStuckPlayback(true);
};
MSEPlayer.prototype._onvProgress = function (e) {
this._checkAndResumeStuckPlayback();
};
MSEPlayer.prototype._createWasmPlayer = function (codecId, duration) {
console.log(codecId, duration);
if (this._wasmPlayer) {
this._wasmPlayer.destroy();
this._wasmPlayer = null;
}
if (codecId === 12) {
this._type === 'wasmPlayer';
var workerPath = this._config.workerPath;
var p = this._wasmPlayer = new WasmPlayer(this._canvasElement, this.isLive, codecId, duration, workerPath);
p.on(EventInfo.ERROR, this._wpOnError.bind(this));
p.on(EventInfo.FIRST_CANPLAY, this._wpOnFirstCanplay.bind(this));
// p.on(l.default.VIDEOSEEK, this._wpOnVideoSeeked.bind(this));
// i.on(l.default.PLAYTIME, this._wpOnPlayTime.bind(this));
// p.onstreamPuase = this._wpOnStreamPause.bind(this);
// p.setPlaybackMode(this._playbackMode, this._playbackTime);
p.initDecodeWorker();
p.play();
// this._emitter.emit(l.default.VIDEOPLAY, {
// index: this._index
// })
}
};
MSEPlayer.prototype._wpOnError = function (e, t) {
console.log(e, t);
};
MSEPlayer.prototype._wpOnFirstCanplay = function (e, t) {
var w = e.w;
var h = e.h;
this._canvasElement.width = w;
this._canvasElement.height = h;
this._onvCanPlay(e, t);
// this._emitter()
};
return MSEPlayer;
}());
export default MSEPlayer;
//# sourceMappingURL=mse-player.js.map