@galacean/effects-plugin-multimedia 2.8.7 → 2.8.9

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
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects player multimedia plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 云垣
6
- * Version: v2.8.7
6
+ * Version: v2.8.9
7
7
  */
8
8
 
9
9
  'use strict';
@@ -653,20 +653,26 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
653
653
  };
654
654
  _proto.onAwake = function onAwake() {
655
655
  var _this = this;
656
- var _this_item_composition, _this_item_composition1, _this_item_composition2;
657
656
  MaskableGraphic.prototype.onAwake.call(this);
658
- (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.on("goto", function(option) {
657
+ var composition = this.item.composition;
658
+ if (!composition) {
659
+ return;
660
+ }
661
+ this.handleGoto = function(option) {
659
662
  _this.setCurrentTime(_this.item.time);
660
- });
661
- (_this_item_composition1 = this.item.composition) == null ? void 0 : _this_item_composition1.on("pause", function() {
663
+ };
664
+ this.handlePause = function() {
662
665
  _this.pauseVideo();
663
- });
664
- (_this_item_composition2 = this.item.composition) == null ? void 0 : _this_item_composition2.on("play", function(option) {
666
+ };
667
+ this.handlePlay = function(option) {
665
668
  if (_this.item.time < 0) {
666
669
  return;
667
670
  }
668
671
  _this.playVideo();
669
- });
672
+ };
673
+ composition.on("goto", this.handleGoto);
674
+ composition.on("pause", this.handlePause);
675
+ composition.on("play", this.handlePlay);
670
676
  };
671
677
  _proto.fromData = function fromData(data) {
672
678
  MaskableGraphic.prototype.fromData.call(this, data);
@@ -710,13 +716,13 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
710
716
  var _this_item = this.item, videoTime = _this_item.time, videoDuration = _this_item.duration, videoEndBehavior = _this_item.endBehavior, composition = _this_item.composition;
711
717
  EFFECTS.assertExist(composition);
712
718
  var _composition_rootItem = composition.rootItem, rootEndBehavior = _composition_rootItem.endBehavior, rootDuration = _composition_rootItem.duration;
713
- // 判断是否处于“结束状态”:
719
+ // 判断是否处于"结束状态":
714
720
  // - 视频时间为 0(未开始)
715
721
  // - 合成时间已达最大时长(播放完毕)
716
722
  // - 视频时间接近或等于其总时长(考虑容差阈值)
717
- var isEnd = videoTime === 0 || composition.time === rootDuration || Math.abs(videoTime - videoDuration) <= this.threshold;
718
- // 如果视频时间大于 0,且未到结束状态,并且尚未触发播放,则开始播放视频
719
- if (videoTime > 0 && !isEnd && !this.played) {
723
+ var isEnd = videoTime === 0 || Math.abs(composition.time - rootDuration) <= this.threshold || Math.abs(videoTime - videoDuration) <= this.threshold;
724
+ // 如果视频时间大于等于 0,且未到结束状态,并且尚未触发播放,则开始播放视频
725
+ if (videoTime >= 0 && !isEnd && !this.played && this.isVideoActive) {
720
726
  this.playVideo();
721
727
  }
722
728
  // 当视频播放时间接近或超过其总时长时,根据其结束行为进行处理
@@ -727,10 +733,6 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
727
733
  this.pauseVideo();
728
734
  }
729
735
  }
730
- // ios freeze issue
731
- // else if (videoEndBehavior === spec.EndBehavior.destroy || videoEndBehavior === spec.EndBehavior.restart) {
732
- // this.setCurrentTime(0);
733
- // }
734
736
  }
735
737
  // 判断整个合成是否接近播放完成
736
738
  // composition.time + threshold >= rootDuration 表示即将结束
@@ -847,15 +849,40 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
847
849
  this.video.pause();
848
850
  };
849
851
  _proto.onDestroy = function onDestroy() {
852
+ var _this_item;
850
853
  MaskableGraphic.prototype.onDestroy.call(this);
854
+ // 清理播放状态
851
855
  this.played = false;
852
856
  this.isPlayLoading = false;
853
857
  this.pendingPause = false;
858
+ this.isVideoActive = false;
859
+ // 清理video资源
854
860
  if (this.video) {
861
+ // 暂停视频
855
862
  this.video.pause();
856
- this.video.src = "";
863
+ // 移除video源,帮助垃圾回收
864
+ this.video.removeAttribute("src");
857
865
  this.video.load();
866
+ // 清理video引用
867
+ this.video = undefined;
868
+ }
869
+ // 清理事件监听
870
+ var composition = (_this_item = this.item) == null ? void 0 : _this_item.composition;
871
+ if (composition) {
872
+ if (this.handleGoto) {
873
+ composition.off("goto", this.handleGoto);
874
+ }
875
+ if (this.handlePause) {
876
+ composition.off("pause", this.handlePause);
877
+ }
878
+ if (this.handlePlay) {
879
+ composition.off("play", this.handlePlay);
880
+ }
858
881
  }
882
+ // 清理处理器引用
883
+ this.handleGoto = undefined;
884
+ this.handlePause = undefined;
885
+ this.handlePlay = undefined;
859
886
  };
860
887
  _proto.onDisable = function onDisable() {
861
888
  MaskableGraphic.prototype.onDisable.call(this);
@@ -865,6 +892,11 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
865
892
  _proto.onEnable = function onEnable() {
866
893
  MaskableGraphic.prototype.onEnable.call(this);
867
894
  this.isVideoActive = true;
895
+ this.played = false;
896
+ // 重播时确保视频同步到当前时间
897
+ if (this.video && this.item.composition) {
898
+ this.setCurrentTime(Math.max(0, this.item.time));
899
+ }
868
900
  this.playVideo();
869
901
  };
870
902
  return VideoComponent;
@@ -1212,7 +1244,7 @@ exports.AudioComponent = __decorate([
1212
1244
 
1213
1245
  /**
1214
1246
  * 插件版本号
1215
- */ var version = "2.8.7";
1247
+ */ var version = "2.8.9";
1216
1248
  EFFECTS.registerPlugin("video", VideoLoader);
1217
1249
  EFFECTS.registerPlugin("audio", AudioLoader);
1218
1250
  EFFECTS.logger.info("Plugin multimedia version: " + version + ".");