@give-tech/ec-player 0.0.1-beta.33 → 0.0.1-beta.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3031,18 +3031,27 @@ class FLVPlayer extends BasePlayer {
3031
3031
  console.log("[FLVPlayer] RenderLoop initialized, firstFrameDts:", this.firstFrameDts, "isLive:", isLive);
3032
3032
  }
3033
3033
  if (isLive) {
3034
- const elapsed = now - this.playStartTime - this.pausedTime;
3035
- const currentTargetDts = this.firstFrameDts + elapsed;
3036
- this.setCurrentTime(Math.floor(currentTargetDts));
3037
- let frameToRender = null;
3038
- while (this._timedFrameBuffer.length > 0 && this._timedFrameBuffer[0].dts <= currentTargetDts) {
3034
+ if (this.lastRenderedDts < 0 && this._timedFrameBuffer.length > 0) {
3035
+ const firstFrame = this._timedFrameBuffer.shift();
3036
+ this.renderFrame(firstFrame, now);
3037
+ this.firstFrameDts = firstFrame.dts;
3038
+ this.playStartTime = now;
3039
+ this.pausedTime = 0;
3040
+ console.log("[FLVPlayer] Live first frame rendered immediately, dts:", firstFrame.dts);
3041
+ } else {
3042
+ const elapsed = now - this.playStartTime - this.pausedTime;
3043
+ const currentTargetDts = this.firstFrameDts + elapsed;
3044
+ this.setCurrentTime(Math.floor(currentTargetDts));
3045
+ let frameToRender = null;
3046
+ while (this._timedFrameBuffer.length > 0 && this._timedFrameBuffer[0].dts <= currentTargetDts) {
3047
+ if (frameToRender) {
3048
+ this.droppedFrames++;
3049
+ }
3050
+ frameToRender = this._timedFrameBuffer.shift();
3051
+ }
3039
3052
  if (frameToRender) {
3040
- this.droppedFrames++;
3053
+ this.renderFrame(frameToRender, now);
3041
3054
  }
3042
- frameToRender = this._timedFrameBuffer.shift();
3043
- }
3044
- if (frameToRender) {
3045
- this.renderFrame(frameToRender, now);
3046
3055
  }
3047
3056
  } else {
3048
3057
  const nextFrame = this._timedFrameBuffer[0];
@@ -3855,6 +3864,13 @@ class Canvas2DRenderer {
3855
3864
  if (!this.ctx) {
3856
3865
  throw new Error("Invalid canvas element");
3857
3866
  }
3867
+ this.clear();
3868
+ }
3869
+ /**
3870
+ * 清除 canvas 内容
3871
+ */
3872
+ clear() {
3873
+ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
3858
3874
  }
3859
3875
  render(frame) {
3860
3876
  const { width, height, data } = frame;