@byteplus/veplayer-plugin 2.10.3-rc.0 → 2.10.3-rc.1

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.
Files changed (31) hide show
  1. package/esm/ad.d.ts +3 -0
  2. package/esm/hlsjs.d.ts +3 -0
  3. package/esm/index.development.js +495 -217
  4. package/esm/index.production.js +1 -1
  5. package/esm/time-shift.d.ts +3 -0
  6. package/esm/veplayer.plugin.abr.development.js +1 -1
  7. package/esm/veplayer.plugin.abr.production.js +1 -1
  8. package/esm/veplayer.plugin.drm.development.js +1 -1
  9. package/esm/veplayer.plugin.drm.production.js +1 -1
  10. package/esm/veplayer.plugin.flv.development.js +1 -1
  11. package/esm/veplayer.plugin.flv.production.js +1 -1
  12. package/esm/veplayer.plugin.hls.development.js +1 -1
  13. package/esm/veplayer.plugin.hls.production.js +1 -1
  14. package/esm/veplayer.plugin.hlsjs.development.js +496 -218
  15. package/esm/veplayer.plugin.hlsjs.production.js +1 -1
  16. package/esm/veplayer.plugin.rtm.development.js +1 -1
  17. package/esm/veplayer.plugin.rtm.production.js +1 -1
  18. package/esm/veplayer.plugin.time.shift.development.js +13 -16
  19. package/esm/veplayer.plugin.time.shift.production.js +1 -1
  20. package/esm/veplayer.plugin.xgvideo.development.js +1 -1
  21. package/esm/veplayer.plugin.xgvideo.production.js +1 -1
  22. package/esm/veplayer.strategy.base.development.js +1 -1
  23. package/esm/veplayer.strategy.base.production.js +1 -1
  24. package/esm/veplayer.strategy.rtm.adaptive.buffer.development.js +1 -1
  25. package/esm/veplayer.strategy.rtm.adaptive.buffer.production.js +1 -1
  26. package/package.json +106 -2
  27. package/umd/ad.d.ts +3 -0
  28. package/umd/hlsjs.d.ts +3 -0
  29. package/umd/time-shift.d.ts +3 -0
  30. package/umd/veplayer.plugin.hlsjs.development.js +495 -217
  31. package/umd/veplayer.plugin.hlsjs.production.js +1 -1
@@ -80224,7 +80224,7 @@ class Hls {
80224
80224
  }
80225
80225
  }
80226
80226
  Hls.defaultConfig = void 0;
80227
- const optionsMap = {
80227
+ const OPTIONS_MAP = {
80228
80228
  liveSyncDuration: {
80229
80229
  key: "targetLatency",
80230
80230
  val: 10
@@ -80241,20 +80241,40 @@ const optionsMap = {
80241
80241
  key: "minSegmentsStartPlay",
80242
80242
  val: 3
80243
80243
  },
80244
- preferManagedMediaSource: {
80245
- key: "preferMMS",
80246
- val: false
80247
- },
80244
+ preferManagedMediaSource: [
80245
+ {
80246
+ key: "preferMMS",
80247
+ val: false
80248
+ },
80249
+ {
80250
+ key: "preferMMSStreaming",
80251
+ val: false
80252
+ }
80253
+ ],
80248
80254
  lowLatencyMode: {
80249
80255
  key: "useLowLatency",
80250
80256
  val: true
80257
+ },
80258
+ startPosition: {
80259
+ key: "startTime",
80260
+ val: 0
80261
+ },
80262
+ interstitialLiveLookAhead: {
80263
+ key: "preloadTime",
80264
+ val: 30
80251
80265
  }
80252
80266
  };
80253
- function getHlsConfig(config2, playerConfig) {
80267
+ function getHlsConfig(config2) {
80254
80268
  const hlsConfig = {};
80255
- Object.keys(optionsMap).forEach((keyStr) => {
80256
- const tmp = optionsMap[keyStr];
80257
- hlsConfig[keyStr] = config2[tmp.key] || tmp.val;
80269
+ Object.keys(OPTIONS_MAP).forEach((keyStr) => {
80270
+ const tmp = OPTIONS_MAP[keyStr];
80271
+ if (tmp instanceof Array) {
80272
+ tmp.forEach((item) => {
80273
+ hlsConfig[keyStr] = item.val;
80274
+ });
80275
+ } else {
80276
+ hlsConfig[keyStr] = config2[tmp.key] || tmp.val;
80277
+ }
80258
80278
  });
80259
80279
  const maxNumRetry = typeof config2.retryCount === "number" ? config2.retryCount : 3;
80260
80280
  const retryDelayMs = typeof config2.retryDelay === "number" ? config2.retryDelay : 1e3;
@@ -80305,11 +80325,434 @@ function getHlsConfig(config2, playerConfig) {
80305
80325
  ...config2
80306
80326
  };
80307
80327
  }
80328
+ function initHlsEvents(hls, player) {
80329
+ hls.on(Hls.Events.SUBTITLE_FRAG_PROCESSED, (_, { frag }) => {
80330
+ player.emit("core_event", {
80331
+ eventName: "core.subtitlesegments",
80332
+ list: frag
80333
+ });
80334
+ });
80335
+ hls.on(Hls.Events.MANIFEST_PARSED, (_, { levels }) => {
80336
+ player.emit("core_event", {
80337
+ eventName: "core.subtitleplaylist",
80338
+ list: levels
80339
+ });
80340
+ });
80341
+ hls.on(Hls.Events.MANIFEST_LOADING, (_, { url: url2 }) => {
80342
+ player.emit("core_event", {
80343
+ eventName: "core.loadstart",
80344
+ url: url2
80345
+ });
80346
+ });
80347
+ hls.on(Hls.Events.LEVEL_LOADING, (_, { url: url2 }) => {
80348
+ player.emit("core_event", {
80349
+ eventName: "core.loadstart",
80350
+ url: url2
80351
+ });
80352
+ });
80353
+ hls.on(Hls.Events.FRAG_LOADING, (_, { frag }) => {
80354
+ player.emit("core_event", {
80355
+ eventName: "core.loadstart",
80356
+ url: frag.url
80357
+ });
80358
+ });
80359
+ hls.on(Hls.Events.MANIFEST_LOADED, (_, data2) => {
80360
+ const { url: url2 } = data2;
80361
+ player.emit("core_event", {
80362
+ eventName: "core.loadcomplete",
80363
+ url: url2
80364
+ });
80365
+ });
80366
+ hls.on(Hls.Events.LEVEL_LOADED, (_, data2) => {
80367
+ const { details, stats } = data2;
80368
+ player.emit("core_event", {
80369
+ eventName: "core.loadcomplete",
80370
+ ...stats,
80371
+ url: details == null ? void 0 : details.url
80372
+ });
80373
+ });
80374
+ hls.on(Hls.Events.FRAG_LOADED, (_, data2) => {
80375
+ const { frag } = data2;
80376
+ player.emit("core_event", {
80377
+ eventName: "core.loadcomplete",
80378
+ url: frag.url
80379
+ });
80380
+ });
80381
+ hls.on(Hls.Events.FRAG_PARSING_USERDATA, (_, { samples }) => {
80382
+ player.emit("core_event", {
80383
+ eventName: "core.sei",
80384
+ sei: samples
80385
+ });
80386
+ });
80387
+ hls.on(Hls.Events.MANIFEST_LOADED, (_, { levels, networkDetails }) => {
80388
+ player.emit("core_event", {
80389
+ eventName: "core.hlsmanifestloaded",
80390
+ playlist: levels
80391
+ });
80392
+ player.emit("core_event", {
80393
+ eventName: "core.loadresponseheaders",
80394
+ headers: networkDetails.headers
80395
+ });
80396
+ });
80397
+ hls.on(Hls.Events.LEVEL_LOADED, (_, { details }) => {
80398
+ const dateRanges = {};
80399
+ Object.keys(details.dateRanges).forEach((key2) => {
80400
+ dateRanges[key2] = details.dateRanges[key2].attr["START-DATE"];
80401
+ });
80402
+ player.emit("core_event", {
80403
+ eventName: "core.hlslevelloaded",
80404
+ playlist: {
80405
+ ...details,
80406
+ segments: details.fragments,
80407
+ dateRanges
80408
+ }
80409
+ });
80410
+ });
80411
+ hls.on(Hls.Events.ERROR, (_, data2) => {
80412
+ const { details, fatal, type, response, reason, error } = data2;
80413
+ if (!fatal) {
80414
+ return;
80415
+ }
80416
+ let errorCode;
80417
+ let errorType;
80418
+ switch (type) {
80419
+ case Hls.ErrorTypes.NETWORK_ERROR:
80420
+ errorCode = 2100;
80421
+ if (details.includes("TimeOut")) {
80422
+ errorCode = 2101;
80423
+ } else if ((response == null ? void 0 : response.code) === 403) {
80424
+ errorCode = 2103;
80425
+ } else if ((response == null ? void 0 : response.code) === 404) {
80426
+ errorCode = 2104;
80427
+ }
80428
+ player.emit("error", {
80429
+ errorType: "network",
80430
+ errorCode,
80431
+ message: (error == null ? void 0 : error.message) || details,
80432
+ originError: data2
80433
+ });
80434
+ break;
80435
+ case Hls.ErrorTypes.MEDIA_ERROR:
80436
+ errorType = "media";
80437
+ if (details === Hls.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR) {
80438
+ errorCode = 5104;
80439
+ } else if (details === Hls.ErrorDetails.FRAG_DECRYPT_ERROR) {
80440
+ errorCode = 5105;
80441
+ } else if (details === Hls.ErrorDetails.FRAG_PARSING_ERROR) {
80442
+ errorCode = 1100;
80443
+ errorType = "manifest";
80444
+ } else if (details === Hls.ErrorDetails.FRAG_GAP) {
80445
+ errorCode = 5104;
80446
+ } else if (details === Hls.ErrorDetails.BUFFER_ADD_CODEC_ERROR) {
80447
+ errorCode = 5200;
80448
+ } else if (details === Hls.ErrorDetails.BUFFER_INCOMPATIBLE_CODECS_ERROR) {
80449
+ errorCode = 5104;
80450
+ } else if (details === Hls.ErrorDetails.BUFFER_APPEND_ERROR) {
80451
+ errorCode = 5201;
80452
+ } else if (details === Hls.ErrorDetails.BUFFER_APPENDING_ERROR) {
80453
+ errorCode = 5201;
80454
+ } else if (details === Hls.ErrorDetails.BUFFER_STALLED_ERROR) {
80455
+ errorCode = 5203;
80456
+ } else if (details === Hls.ErrorDetails.BUFFER_FULL_ERROR) {
80457
+ errorCode = 5203;
80458
+ } else if (details === Hls.ErrorDetails.BUFFER_SEEK_OVER_HOLE) {
80459
+ errorCode = 5202;
80460
+ } else if (details === Hls.ErrorDetails.BUFFER_NUDGE_ON_STALL) {
80461
+ errorCode = 5202;
80462
+ }
80463
+ player.emit("error", {
80464
+ errorType: errorType || type,
80465
+ errorCode,
80466
+ message: (error == null ? void 0 : error.message) || details,
80467
+ originError: data2
80468
+ });
80469
+ break;
80470
+ case Hls.ErrorTypes.MUX_ERROR:
80471
+ errorCode = 4100;
80472
+ player.emit("error", {
80473
+ errorType: "remux",
80474
+ errorCode,
80475
+ message: (error == null ? void 0 : error.message) || details,
80476
+ originError: data2
80477
+ });
80478
+ break;
80479
+ case Hls.ErrorTypes.KEY_SYSTEM_ERROR:
80480
+ errorCode = 7111;
80481
+ if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_KEYS) {
80482
+ errorCode = 7103;
80483
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_ACCESS) {
80484
+ errorCode = 7101;
80485
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_SESSION) {
80486
+ errorCode = 7104;
80487
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_CONFIGURED_LICENSE) {
80488
+ errorCode = 7107;
80489
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED) {
80490
+ errorCode = 7108;
80491
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED) {
80492
+ errorCode = 7110;
80493
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED) {
80494
+ errorCode = 7110;
80495
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_SESSION_UPDATE_FAILED) {
80496
+ errorCode = 7104;
80497
+ } else if (details === Hls.ErrorDetails.KEY_SYSTEM_STATUS_INTERNAL_ERROR) {
80498
+ errorCode = 7111;
80499
+ }
80500
+ player.emit("error", {
80501
+ errorType: "drm",
80502
+ errorCode,
80503
+ message: (error == null ? void 0 : error.message) || reason || details,
80504
+ originError: data2
80505
+ });
80506
+ break;
80507
+ default:
80508
+ if (details === Hls.ErrorDetails.LEVEL_SWITCH_ERROR) {
80509
+ errorCode = 2100;
80510
+ errorType = "network";
80511
+ }
80512
+ player.emit("error", {
80513
+ errorType: errorType || "other",
80514
+ errorCode,
80515
+ message: (error == null ? void 0 : error.message) || reason || details,
80516
+ originError: data2
80517
+ });
80518
+ break;
80519
+ }
80520
+ try {
80521
+ hls.stopLoad();
80522
+ player.pause();
80523
+ } catch (error2) {
80524
+ }
80525
+ });
80526
+ hls.on(Hls.Events.MEDIA_ATTACHED, () => {
80527
+ player.emit("sourceopen");
80528
+ });
80529
+ hls.on(Hls.Events.BUFFER_APPENDED, () => {
80530
+ player.emit("bufferappend");
80531
+ });
80532
+ hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_, { audioTracks }) => {
80533
+ player.emit("core_event", {
80534
+ eventName: "core.audiotracksupdate",
80535
+ audioTracks
80536
+ });
80537
+ });
80538
+ hls.on(Hls.Events.AUDIO_TRACK_SWITCHING, (_, data2) => {
80539
+ player.emit("core_event", {
80540
+ eventName: "core.audiotrackswitching",
80541
+ ...data2
80542
+ });
80543
+ });
80544
+ hls.on(Hls.Events.AUDIO_TRACK_SWITCHED, (_, data2) => {
80545
+ player.emit("core_event", {
80546
+ eventName: "core.audiotrackswitched",
80547
+ ...data2
80548
+ });
80549
+ });
80550
+ hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED, (_, { subtitleTracks }) => {
80551
+ player.emit("core_event", {
80552
+ eventName: "core.subtitletracksupdate",
80553
+ subtitleTracks
80554
+ });
80555
+ });
80556
+ hls.on(Hls.Events.SUBTITLE_TRACKS_CLEARED, () => {
80557
+ player.emit("core_event", {
80558
+ eventName: "core.subtitletracksclear"
80559
+ });
80560
+ });
80561
+ hls.on(Hls.Events.SUBTITLE_TRACK_SWITCH, (_, data2) => {
80562
+ player.emit("core_event", {
80563
+ eventName: "core.subtitletrackswitch",
80564
+ ...data2
80565
+ });
80566
+ });
80567
+ hls.on(Hls.Events.SUBTITLE_TRACK_LOADING, (_, data2) => {
80568
+ player.emit("core_event", {
80569
+ eventName: "core.subtitletrackloading",
80570
+ ...data2
80571
+ });
80572
+ });
80573
+ hls.on(Hls.Events.SUBTITLE_TRACK_LOADED, (_, data2) => {
80574
+ player.emit("core_event", {
80575
+ eventName: "core.subtitletrackloaded",
80576
+ ...data2
80577
+ });
80578
+ });
80579
+ }
80580
+ class TrackManager {
80581
+ constructor(hls, player) {
80582
+ this.hls = hls;
80583
+ this.player = player;
80584
+ }
80585
+ // Audio Track Methods
80586
+ getAudioTracks() {
80587
+ if (!this.hls) {
80588
+ console.warn("HLS instance not initialized");
80589
+ return [];
80590
+ }
80591
+ try {
80592
+ return this.hls.audioTracks || [];
80593
+ } catch (error) {
80594
+ console.error("Failed to get audio tracks:", error);
80595
+ return [];
80596
+ }
80597
+ }
80598
+ getCurrentAudioTrack() {
80599
+ if (!this.hls) {
80600
+ console.warn("HLS instance not initialized");
80601
+ return -1;
80602
+ }
80603
+ try {
80604
+ return this.hls.audioTrack;
80605
+ } catch (error) {
80606
+ console.error("Failed to get current audio track:", error);
80607
+ return -1;
80608
+ }
80609
+ }
80610
+ switchAudioTrack(trackId) {
80611
+ if (!this.hls) {
80612
+ console.warn("HLS instance not initialized");
80613
+ return false;
80614
+ }
80615
+ const audioTracks = this.getAudioTracks();
80616
+ if (audioTracks.length === 0) {
80617
+ console.warn("No audio tracks available");
80618
+ return false;
80619
+ }
80620
+ const trackExists = audioTracks.some((_, index2) => index2 === trackId);
80621
+ if (!trackExists) {
80622
+ console.warn(`Audio track with ID ${trackId} not found`);
80623
+ return false;
80624
+ }
80625
+ try {
80626
+ this.hls.audioTrack = trackId;
80627
+ this.player.emit("core_event", {
80628
+ eventName: "core.audiotrackchange",
80629
+ trackId,
80630
+ trackInfo: audioTracks[trackId] || null
80631
+ });
80632
+ return true;
80633
+ } catch (error) {
80634
+ console.error("Failed to switch audio track:", error);
80635
+ return false;
80636
+ }
80637
+ }
80638
+ // Subtitle Track Methods
80639
+ getSubtitleTracks() {
80640
+ if (!this.hls) {
80641
+ console.warn("HLS instance not initialized");
80642
+ return [];
80643
+ }
80644
+ try {
80645
+ return this.hls.subtitleTracks || [];
80646
+ } catch (error) {
80647
+ console.error("Failed to get subtitle tracks:", error);
80648
+ return [];
80649
+ }
80650
+ }
80651
+ getAllSubtitleTracks() {
80652
+ if (!this.hls) {
80653
+ console.warn("HLS instance not initialized");
80654
+ return [];
80655
+ }
80656
+ try {
80657
+ return this.hls.allSubtitleTracks || [];
80658
+ } catch (error) {
80659
+ console.error("Failed to get all subtitle tracks:", error);
80660
+ return [];
80661
+ }
80662
+ }
80663
+ getCurrentSubtitleTrack() {
80664
+ if (!this.hls) {
80665
+ console.warn("HLS instance not initialized");
80666
+ return -1;
80667
+ }
80668
+ try {
80669
+ return this.hls.subtitleTrack;
80670
+ } catch (error) {
80671
+ console.error("Failed to get current subtitle track:", error);
80672
+ return -1;
80673
+ }
80674
+ }
80675
+ switchSubtitleTrack(trackId) {
80676
+ if (!this.hls) {
80677
+ console.warn("HLS instance not initialized");
80678
+ return false;
80679
+ }
80680
+ const subtitleTracks = this.getSubtitleTracks();
80681
+ if (trackId === -1) {
80682
+ try {
80683
+ this.hls.subtitleTrack = -1;
80684
+ this.player.emit("core_event", {
80685
+ eventName: "core.subtitletrackchange",
80686
+ trackId: -1,
80687
+ trackInfo: null
80688
+ });
80689
+ return true;
80690
+ } catch (error) {
80691
+ console.error("Failed to disable subtitle track:", error);
80692
+ return false;
80693
+ }
80694
+ }
80695
+ if (subtitleTracks.length === 0) {
80696
+ console.warn("No subtitle tracks available");
80697
+ return false;
80698
+ }
80699
+ const trackExists = subtitleTracks.some((_, index2) => index2 === trackId);
80700
+ if (!trackExists) {
80701
+ console.warn(`Subtitle track with ID ${trackId} not found`);
80702
+ return false;
80703
+ }
80704
+ try {
80705
+ this.hls.subtitleTrack = trackId;
80706
+ this.player.emit("core_event", {
80707
+ eventName: "core.subtitletrackchange",
80708
+ trackId,
80709
+ trackInfo: subtitleTracks[trackId] || null
80710
+ });
80711
+ return true;
80712
+ } catch (error) {
80713
+ console.error("Failed to switch subtitle track:", error);
80714
+ return false;
80715
+ }
80716
+ }
80717
+ getSubtitleDisplay() {
80718
+ if (!this.hls) {
80719
+ console.warn("HLS instance not initialized");
80720
+ return false;
80721
+ }
80722
+ try {
80723
+ return this.hls.subtitleDisplay;
80724
+ } catch (error) {
80725
+ console.error("Failed to get subtitle display status:", error);
80726
+ return false;
80727
+ }
80728
+ }
80729
+ setSubtitleDisplay(enabled) {
80730
+ if (!this.hls) {
80731
+ console.warn("HLS instance not initialized");
80732
+ return false;
80733
+ }
80734
+ try {
80735
+ this.hls.subtitleDisplay = enabled;
80736
+ this.player.emit("core_event", {
80737
+ eventName: "core.subtitledisplaychange",
80738
+ enabled
80739
+ });
80740
+ return true;
80741
+ } catch (error) {
80742
+ console.error("Failed to set subtitle display:", error);
80743
+ return false;
80744
+ }
80745
+ }
80746
+ }
80308
80747
  const MAX_HOLE = 0.1;
80309
80748
  class XgHls extends BasePlugin$1 {
80310
80749
  constructor(options) {
80311
- super(options);
80750
+ super({
80751
+ ...options,
80752
+ pluginName: XgHls.pluginName
80753
+ });
80312
80754
  this._tickInterval = 500;
80755
+ this._currentIndex = 0;
80313
80756
  this._onPlay = () => {
80314
80757
  this.hls.startLoad();
80315
80758
  };
@@ -80347,8 +80790,7 @@ class XgHls extends BasePlugin$1 {
80347
80790
  var _a;
80348
80791
  (_a = this.hls) == null ? void 0 : _a.on(eventName, func);
80349
80792
  };
80350
- const config2 = options.config || {};
80351
- this.config = config2;
80793
+ this.config = options.config || {};
80352
80794
  this.player.handleSource = false;
80353
80795
  }
80354
80796
  static get pluginName() {
@@ -80358,209 +80800,7 @@ class XgHls extends BasePlugin$1 {
80358
80800
  this.register(this.player.config.url);
80359
80801
  }
80360
80802
  initEvt() {
80361
- this.hls.on(Hls.Events.SUBTITLE_FRAG_PROCESSED, (_, { frag }) => {
80362
- this.player.emit("core_event", {
80363
- eventName: "core.subtitlesegments",
80364
- list: frag
80365
- });
80366
- });
80367
- this.hls.on(Hls.Events.MANIFEST_PARSED, (_, { levels }) => {
80368
- this.player.emit("core_event", {
80369
- eventName: "core.subtitleplaylist",
80370
- list: levels
80371
- });
80372
- });
80373
- this.hls.on(Hls.Events.MANIFEST_LOADING, (_, { url: url2 }) => {
80374
- this.player.emit("core_event", {
80375
- eventName: "core.loadstart",
80376
- url: url2
80377
- });
80378
- });
80379
- this.hls.on(Hls.Events.LEVEL_LOADING, (_, { url: url2 }) => {
80380
- this.player.emit("core_event", {
80381
- eventName: "core.loadstart",
80382
- url: url2
80383
- });
80384
- });
80385
- this.hls.on(Hls.Events.FRAG_LOADING, (_, { frag }) => {
80386
- this.player.emit("core_event", {
80387
- eventName: "core.loadstart",
80388
- url: frag.url
80389
- });
80390
- });
80391
- this.hls.on(Hls.Events.MANIFEST_LOADED, (_, data2) => {
80392
- const { url: url2 } = data2;
80393
- this.player.emit("core_event", {
80394
- eventName: "core.loadcomplete",
80395
- url: url2
80396
- });
80397
- });
80398
- this.hls.on(Hls.Events.LEVEL_LOADED, (_, data2) => {
80399
- const { details, stats } = data2;
80400
- this.player.emit("core_event", {
80401
- eventName: "core.loadcomplete",
80402
- ...stats,
80403
- url: details == null ? void 0 : details.url
80404
- });
80405
- });
80406
- this.hls.on(Hls.Events.FRAG_LOADED, (_, data2) => {
80407
- const { frag } = data2;
80408
- this.player.emit("core_event", {
80409
- eventName: "core.loadcomplete",
80410
- url: frag.url
80411
- });
80412
- });
80413
- this.hls.on(Hls.Events.FRAG_PARSING_USERDATA, (_, { samples }) => {
80414
- this.player.emit("core_event", {
80415
- eventName: "core.sei",
80416
- sei: samples
80417
- });
80418
- });
80419
- this.hls.on(Hls.Events.MANIFEST_LOADED, (_, { levels, networkDetails }) => {
80420
- this.player.emit("core_event", {
80421
- eventName: "core.hlsmanifestloaded",
80422
- playlist: levels
80423
- });
80424
- this.player.emit("core_event", {
80425
- eventName: "core.loadresponseheaders",
80426
- headers: networkDetails.headers
80427
- });
80428
- });
80429
- this.hls.on(Hls.Events.LEVEL_LOADED, (_, { details }) => {
80430
- const dateRanges = {};
80431
- Object.keys(details.dateRanges).forEach((key2) => {
80432
- dateRanges[key2] = details.dateRanges[key2].attr["START-DATE"];
80433
- });
80434
- this.player.emit("core_event", {
80435
- eventName: "core.hlslevelloaded",
80436
- playlist: {
80437
- ...details,
80438
- segments: details.fragments,
80439
- dateRanges
80440
- }
80441
- });
80442
- });
80443
- this.hls.on(Hls.Events.ERROR, (_, data2) => {
80444
- const { details, fatal, type, response, reason, error } = data2;
80445
- if (!fatal) {
80446
- return;
80447
- }
80448
- let errorCode;
80449
- let errorType;
80450
- switch (type) {
80451
- case Hls.ErrorTypes.NETWORK_ERROR:
80452
- errorCode = 2100;
80453
- if (details.includes("TimeOut")) {
80454
- errorCode = 2101;
80455
- } else if ((response == null ? void 0 : response.code) === 403) {
80456
- errorCode = 2103;
80457
- } else if ((response == null ? void 0 : response.code) === 404) {
80458
- errorCode = 2104;
80459
- }
80460
- this.player.emit("error", {
80461
- errorType: "network",
80462
- errorCode,
80463
- message: (error == null ? void 0 : error.message) || details,
80464
- originError: data2
80465
- });
80466
- break;
80467
- case Hls.ErrorTypes.MEDIA_ERROR:
80468
- errorType = "media";
80469
- if (details === Hls.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR) {
80470
- errorCode = 5104;
80471
- } else if (details === Hls.ErrorDetails.FRAG_DECRYPT_ERROR) {
80472
- errorCode = 5105;
80473
- } else if (details === Hls.ErrorDetails.FRAG_PARSING_ERROR) {
80474
- errorCode = 1100;
80475
- errorType = "manifest";
80476
- } else if (details === Hls.ErrorDetails.FRAG_GAP) {
80477
- errorCode = 5104;
80478
- } else if (details === Hls.ErrorDetails.BUFFER_ADD_CODEC_ERROR) {
80479
- errorCode = 5200;
80480
- } else if (details === Hls.ErrorDetails.BUFFER_INCOMPATIBLE_CODECS_ERROR) {
80481
- errorCode = 5104;
80482
- } else if (details === Hls.ErrorDetails.BUFFER_APPEND_ERROR) {
80483
- errorCode = 5201;
80484
- } else if (details === Hls.ErrorDetails.BUFFER_APPENDING_ERROR) {
80485
- errorCode = 5201;
80486
- } else if (details === Hls.ErrorDetails.BUFFER_STALLED_ERROR) {
80487
- errorCode = 5203;
80488
- } else if (details === Hls.ErrorDetails.BUFFER_FULL_ERROR) {
80489
- errorCode = 5203;
80490
- } else if (details === Hls.ErrorDetails.BUFFER_SEEK_OVER_HOLE) {
80491
- errorCode = 5202;
80492
- } else if (details === Hls.ErrorDetails.BUFFER_NUDGE_ON_STALL) {
80493
- errorCode = 5202;
80494
- }
80495
- this.player.emit("error", {
80496
- errorType: errorType || type,
80497
- errorCode,
80498
- message: (error == null ? void 0 : error.message) || details,
80499
- originError: data2
80500
- });
80501
- break;
80502
- case Hls.ErrorTypes.MUX_ERROR:
80503
- errorCode = 4100;
80504
- this.player.emit("error", {
80505
- errorType: "remux",
80506
- errorCode,
80507
- message: (error == null ? void 0 : error.message) || details,
80508
- originError: data2
80509
- });
80510
- break;
80511
- case Hls.ErrorTypes.KEY_SYSTEM_ERROR:
80512
- errorCode = 7111;
80513
- if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_KEYS) {
80514
- errorCode = 7103;
80515
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_ACCESS) {
80516
- errorCode = 7101;
80517
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_SESSION) {
80518
- errorCode = 7104;
80519
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_NO_CONFIGURED_LICENSE) {
80520
- errorCode = 7107;
80521
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED) {
80522
- errorCode = 7108;
80523
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED) {
80524
- errorCode = 7110;
80525
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED) {
80526
- errorCode = 7110;
80527
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_SESSION_UPDATE_FAILED) {
80528
- errorCode = 7104;
80529
- } else if (details === Hls.ErrorDetails.KEY_SYSTEM_STATUS_INTERNAL_ERROR) {
80530
- errorCode = 7111;
80531
- }
80532
- this.player.emit("error", {
80533
- errorType: "drm",
80534
- errorCode,
80535
- message: (error == null ? void 0 : error.message) || reason || details,
80536
- originError: data2
80537
- });
80538
- break;
80539
- default:
80540
- if (details === Hls.ErrorDetails.LEVEL_SWITCH_ERROR) {
80541
- errorCode = 2100;
80542
- errorType = "network";
80543
- }
80544
- this.player.emit("error", {
80545
- errorType: errorType || "other",
80546
- errorCode,
80547
- message: (error == null ? void 0 : error.message) || reason || details,
80548
- originError: data2
80549
- });
80550
- break;
80551
- }
80552
- try {
80553
- this.hls.stopLoad();
80554
- this.player.pause();
80555
- } catch (error2) {
80556
- }
80557
- });
80558
- this.hls.on(Hls.Events.MEDIA_ATTACHED, () => {
80559
- this.player.emit("sourceopen");
80560
- });
80561
- this.hls.on(Hls.Events.BUFFER_APPENDED, () => {
80562
- this.player.emit("bufferappend");
80563
- });
80803
+ initHlsEvents(this.hls, this.player);
80564
80804
  }
80565
80805
  afterCreate() {
80566
80806
  const media = this.player.media;
@@ -80586,8 +80826,9 @@ class XgHls extends BasePlugin$1 {
80586
80826
  if (this.hls) {
80587
80827
  this.hls.destroy();
80588
80828
  }
80589
- const hlsConfig = getHlsConfig(this.config, player.config);
80829
+ const hlsConfig = getHlsConfig(this.config);
80590
80830
  this.hls = new Hls(hlsConfig);
80831
+ this._trackManager = new TrackManager(this.hls, this.player);
80591
80832
  this.initEvt();
80592
80833
  if (player.config.preProcessUrl) {
80593
80834
  const { url: newUrl } = player.config.preProcessUrl(url2);
@@ -80601,10 +80842,47 @@ class XgHls extends BasePlugin$1 {
80601
80842
  media.removeEventListener("play", this._onPlay);
80602
80843
  media.addEventListener("play", this._onPlay);
80603
80844
  }
80845
+ switchUrl(url2, { startTime, bitrate, seamless }) {
80846
+ this.hls.loadSource(url2);
80847
+ if (startTime !== void 0) {
80848
+ const media = this.player.media;
80849
+ media.currentTime = startTime;
80850
+ }
80851
+ }
80852
+ // Audio Track Methods
80853
+ getAudioTracks() {
80854
+ return this._trackManager.getAudioTracks();
80855
+ }
80856
+ getCurrentAudioTrack() {
80857
+ return this._trackManager.getCurrentAudioTrack();
80858
+ }
80859
+ switchAudioTrack(trackId) {
80860
+ return this._trackManager.switchAudioTrack(trackId);
80861
+ }
80862
+ // Subtitle Track Methods
80863
+ getSubtitleTracks() {
80864
+ return this._trackManager.getSubtitleTracks();
80865
+ }
80866
+ getAllSubtitleTracks() {
80867
+ return this._trackManager.getAllSubtitleTracks();
80868
+ }
80869
+ getCurrentSubtitleTrack() {
80870
+ return this._trackManager.getCurrentSubtitleTrack();
80871
+ }
80872
+ switchSubtitleTrack(trackId) {
80873
+ return this._trackManager.switchSubtitleTrack(trackId);
80874
+ }
80875
+ getSubtitleDisplay() {
80876
+ return this._trackManager.getSubtitleDisplay();
80877
+ }
80878
+ setSubtitleDisplay(enabled) {
80879
+ return this._trackManager.setSubtitleDisplay(enabled);
80880
+ }
80604
80881
  destroy() {
80882
+ var _a;
80605
80883
  clearTimeout(this._tickTimer);
80606
80884
  this.player.off(URL_CHANGE, this.onUrlChange);
80607
- this.hls.destroy();
80885
+ (_a = this.hls) == null ? void 0 : _a.destroy();
80608
80886
  }
80609
80887
  }
80610
80888
  class HlsPlugin extends XgHls {