@give-tech/ec-player 0.0.1-beta.44 → 0.0.1-beta.46

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
@@ -1941,6 +1941,16 @@ class HLSPlayer extends BasePlayer {
1941
1941
  * 销毁播放器,释放所有资源
1942
1942
  */
1943
1943
  destroy() {
1944
+ console.log("[HLSPlayer] Destroying player...");
1945
+ this.isPlaying = false;
1946
+ this.decodeLoopAbort = true;
1947
+ if (this.frameTimer !== null) {
1948
+ cancelAnimationFrame(this.frameTimer);
1949
+ this.frameTimer = null;
1950
+ }
1951
+ if (this.prefetcher) {
1952
+ this.prefetcher.stop();
1953
+ }
1944
1954
  if (this.abortController) {
1945
1955
  this.abortController.abort();
1946
1956
  this.abortController = null;
@@ -1954,6 +1964,7 @@ class HLSPlayer extends BasePlayer {
1954
1964
  this.hevcDecoder = null;
1955
1965
  }
1956
1966
  super.destroy();
1967
+ console.log("[HLSPlayer] Player destroyed");
1957
1968
  }
1958
1969
  /**
1959
1970
  * 跳转到指定时间
@@ -2006,6 +2017,14 @@ class HLSPlayer extends BasePlayer {
2006
2017
  async decodeLoop() {
2007
2018
  console.log("[DecodeLoop] START, isFMP4:", this.isFMP4);
2008
2019
  let batchCount = 0;
2020
+ const READY_TIMEOUT_MS = 5e3;
2021
+ const readyTimeoutId = setTimeout(() => {
2022
+ if (!this.readyFired) {
2023
+ console.warn("[HLSPlayer] Ready timeout, triggering onReady anyway");
2024
+ this.readyFired = true;
2025
+ this.callbacks.onReady?.();
2026
+ }
2027
+ }, READY_TIMEOUT_MS);
2009
2028
  while (this.isPlaying && !this.decodeLoopAbort) {
2010
2029
  const sampleQueueSize = this.sampleQueue.length;
2011
2030
  const maxSamplesBeforePause = this.config.maxQueueSize * 3;
@@ -2112,6 +2131,7 @@ class HLSPlayer extends BasePlayer {
2112
2131
  await this.sleep(2);
2113
2132
  }
2114
2133
  }
2134
+ clearTimeout(readyTimeoutId);
2115
2135
  console.log("[DecodeLoop] END, batches:", batchCount);
2116
2136
  }
2117
2137
  /**
@@ -3416,8 +3436,8 @@ class FLVPlayer extends BasePlayer {
3416
3436
  * 开始播放(覆盖基类方法)
3417
3437
  */
3418
3438
  async play() {
3419
- const MIN_BUFFER_SIZE = this.config.isLive ? 3 : this.dynamicMinBufferSize;
3420
- const MAX_WAIT_TIME = this.config.isLive ? 3e3 : 1e4;
3439
+ const MIN_BUFFER_SIZE = 2;
3440
+ const MAX_WAIT_TIME = this.config.isLive ? 1e3 : 5e3;
3421
3441
  const startTime = Date.now();
3422
3442
  console.log(`[FLVPlayer] Waiting for buffer (target: ${MIN_BUFFER_SIZE} frames)...`);
3423
3443
  let aggressiveDecodeCount = 0;
@@ -3451,6 +3471,11 @@ class FLVPlayer extends BasePlayer {
3451
3471
  }
3452
3472
  }
3453
3473
  console.log("[FLVPlayer] Buffer ready, frames:", this._timedFrameBuffer.length, "queue:", this._videoTagQueue.length);
3474
+ if (!this.readyFired) {
3475
+ console.warn("[FLVPlayer] No frames decoded after buffer wait, triggering onReady anyway");
3476
+ this.readyFired = true;
3477
+ this.callbacks.onReady?.();
3478
+ }
3454
3479
  if (this._timedFrameBuffer.length > 0) {
3455
3480
  if (this.config.isLive && this._timedFrameBuffer.length > 60) {
3456
3481
  const droppedCount = this._timedFrameBuffer.length - 30;
@@ -3487,7 +3512,22 @@ class FLVPlayer extends BasePlayer {
3487
3512
  * 销毁播放器,释放所有资源
3488
3513
  */
3489
3514
  destroy() {
3515
+ console.log("[FLVPlayer] Destroying player...");
3516
+ this.isPlaying = false;
3517
+ this.decodeLoopAbort = true;
3518
+ if (this.frameTimer !== null) {
3519
+ cancelAnimationFrame(this.frameTimer);
3520
+ this.frameTimer = null;
3521
+ }
3522
+ if (this.prefetcher) {
3523
+ this.prefetcher.stop();
3524
+ this.prefetcher.cancelDownload();
3525
+ }
3490
3526
  this.stopLiveDownload();
3527
+ if (this.prefetcher) {
3528
+ this.prefetcher.reset();
3529
+ this.prefetcher = null;
3530
+ }
3491
3531
  if (this.h264Decoder) {
3492
3532
  this.h264Decoder.destroy();
3493
3533
  this.h264Decoder = null;
@@ -3496,11 +3536,8 @@ class FLVPlayer extends BasePlayer {
3496
3536
  this.hevcDecoder.destroy();
3497
3537
  this.hevcDecoder = null;
3498
3538
  }
3499
- if (this.prefetcher) {
3500
- this.prefetcher.reset();
3501
- this.prefetcher = null;
3502
- }
3503
3539
  super.destroy();
3540
+ console.log("[FLVPlayer] Player destroyed");
3504
3541
  }
3505
3542
  /**
3506
3543
  * 处理预取缓冲区数据(供预取器调用)
@@ -3680,8 +3717,8 @@ class FLVPlayer extends BasePlayer {
3680
3717
  }
3681
3718
  const chunks = [];
3682
3719
  let totalLength = 0;
3683
- const MIN_DATA_SIZE = isLive ? 100 * 1024 : 500 * 1024;
3684
- const TIMEOUT_MS = isLive ? 5e3 : 8e3;
3720
+ const MIN_DATA_SIZE = isLive ? 30 * 1024 : 64 * 1024;
3721
+ const TIMEOUT_MS = isLive ? 2e3 : 5e3;
3685
3722
  const startTime = Date.now();
3686
3723
  let started = false;
3687
3724
  let lastLoggedTags = 0;