@galacean/effects-plugin-multimedia 2.9.0 → 2.9.1-beta.0

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.mjs 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.9.0
6
+ * Version: v2.9.1-beta.0
7
7
  */
8
8
 
9
9
  import * as EFFECTS from '@galacean/effects';
@@ -745,10 +745,14 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
745
745
  _proto.onDisable = function onDisable() {
746
746
  MaskableGraphic.prototype.onDisable.call(this);
747
747
  this.isVideoActive = false;
748
+ this.playTriggered = false;
749
+ this.pauseVideoElement();
748
750
  };
749
751
  _proto.onEnable = function onEnable() {
750
752
  MaskableGraphic.prototype.onEnable.call(this);
751
753
  this.isVideoActive = true;
754
+ this.playTriggered = false;
755
+ this.syncVideoToItemTime();
752
756
  };
753
757
  /**
754
758
  * 处理 goto 事件:重置播放状态,记录待 seek 时间
@@ -757,7 +761,7 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
757
761
  this.isWaitingForGotoResult = true;
758
762
  this.playTriggered = false;
759
763
  this.manualPause = false;
760
- this.pendingSeekTime = this.item.time;
764
+ this.pendingSeekTime = this.getItemSeekTime();
761
765
  };
762
766
  /**
763
767
  * 处理合成 pause 事件
@@ -768,7 +772,7 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
768
772
  this.isWaitingForGotoResult = false;
769
773
  if (this.video && this.video.readyState >= 2) {
770
774
  this.isGotoAndStopSeeking = true;
771
- this.performSeek(this.item.time, false, true);
775
+ this.performSeek(this.getItemSeekTime(), false, true);
772
776
  }
773
777
  return;
774
778
  }
@@ -786,7 +790,7 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
786
790
  if (!this.checkCompositionEnded()) {
787
791
  var _this_video;
788
792
  // 如果正在 seeking,不恢复播放,等 seek 完成后再恢复
789
- if (!this.manualPause && !this.videoSeeking && ((_this_video = this.video) == null ? void 0 : _this_video.paused)) {
793
+ if (this.canPlayCurrentItem() && ((_this_video = this.video) == null ? void 0 : _this_video.paused)) {
790
794
  this.safePlay();
791
795
  }
792
796
  return;
@@ -859,14 +863,10 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
859
863
  /**
860
864
  * 是否应该启动视频播放
861
865
  */ _proto.shouldStartVideo = function shouldStartVideo() {
862
- if (this.playTriggered || this.manualPause || this.videoDestroyed || this.checkVideoEnded()) {
863
- return false;
864
- }
865
- var composition = this.item.composition;
866
- if (!composition) {
866
+ if (this.playTriggered || !this.canPlayCurrentItem()) {
867
867
  return false;
868
868
  }
869
- return this.video.currentTime > 0 || composition.time > 0;
869
+ return true;
870
870
  };
871
871
  /**
872
872
  * 处理延迟 seek,返回 true 表示本帧已处理 seek,应跳过后续逻辑
@@ -997,8 +997,25 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
997
997
  var _this = this;
998
998
  if (clearTexture === void 0) clearTexture = false;
999
999
  if (isGotoAndStop === void 0) isGotoAndStop = false;
1000
+ time = this.getClampedSeekTime(time);
1000
1001
  var wasPlaying = !this.video.paused;
1002
+ var isNoopSeek = function() {
1003
+ return !clearTexture && Math.abs(_this.video.currentTime - time) <= VideoComponent.threshold;
1004
+ };
1005
+ var finishNoopSeek = function() {
1006
+ _this.videoSeeking = false;
1007
+ _this.isGotoAndStopSeeking = false;
1008
+ if (isGotoAndStop) {
1009
+ _this.video.pause();
1010
+ } else if (wasPlaying && !_this.manualPause) {
1011
+ _this.safePlay();
1012
+ }
1013
+ };
1001
1014
  var doSeek = function() {
1015
+ if (isNoopSeek()) {
1016
+ finishNoopSeek();
1017
+ return;
1018
+ }
1002
1019
  _this.videoSeeking = true;
1003
1020
  if (clearTexture) {
1004
1021
  _this.material.setTexture("_MainTex", _this.engine.transparentTexture);
@@ -1028,6 +1045,8 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
1028
1045
  if (wasPlaying) {
1029
1046
  // 视频正在播放,直接 seek
1030
1047
  doSeek();
1048
+ } else if (isNoopSeek()) {
1049
+ finishNoopSeek();
1031
1050
  } else {
1032
1051
  // 视频暂停,先 play() 再 seek
1033
1052
  this.video.play().then(function() {
@@ -1065,6 +1084,60 @@ var VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
1065
1084
  }
1066
1085
  };
1067
1086
  /**
1087
+ * 当前 item 可播放的本地视频时间。
1088
+ * item.time 在 delay 前为负数,视频时间需要从 0 开始。
1089
+ */ _proto.getItemSeekTime = function getItemSeekTime() {
1090
+ return Math.max(0, this.getItemLocalTime());
1091
+ };
1092
+ /**
1093
+ * 获取 item 的本地时间。优先使用 timeline 写入的 item.time,
1094
+ * 未写入时使用合成时间和 item delay 做兜底。
1095
+ */ _proto.getItemLocalTime = function getItemLocalTime() {
1096
+ if (this.item.time >= 0) {
1097
+ return this.item.time;
1098
+ }
1099
+ var composition = this.item.composition;
1100
+ if (!composition) {
1101
+ return this.item.time;
1102
+ }
1103
+ var _this_item_definition_delay;
1104
+ return composition.time - ((_this_item_definition_delay = this.item.definition.delay) != null ? _this_item_definition_delay : 0);
1105
+ };
1106
+ /**
1107
+ * 将 seek 目标限制到视频有效时间范围内。
1108
+ */ _proto.getClampedSeekTime = function getClampedSeekTime(time) {
1109
+ var _this_video;
1110
+ var seekTime = Math.max(0, time);
1111
+ var duration = (_this_video = this.video) == null ? void 0 : _this_video.duration;
1112
+ if (!duration || !isFinite(duration)) {
1113
+ return seekTime;
1114
+ }
1115
+ return Math.min(seekTime, duration);
1116
+ };
1117
+ /**
1118
+ * 组件重新启用时将视频时间对齐到 item 本地时间,但不直接触发播放。
1119
+ */ _proto.syncVideoToItemTime = function syncVideoToItemTime() {
1120
+ if (!this.video) {
1121
+ return;
1122
+ }
1123
+ var seekTime = this.getItemSeekTime();
1124
+ var clampedSeekTime = this.getClampedSeekTime(seekTime);
1125
+ if (Math.abs(this.video.currentTime - clampedSeekTime) > VideoComponent.threshold) {
1126
+ this.pendingSeekTime = clampedSeekTime;
1127
+ }
1128
+ };
1129
+ /**
1130
+ * 当前 item 已经进入自己的时间区间,且视频允许自动播放。
1131
+ */ _proto.canPlayCurrentItem = function canPlayCurrentItem() {
1132
+ if (!this.video || !this.isVideoActive || this.getItemLocalTime() < 0) {
1133
+ return false;
1134
+ }
1135
+ if (this.manualPause || this.videoDestroyed || this.videoSeeking || this.pendingSeekTime !== null) {
1136
+ return false;
1137
+ }
1138
+ return !this.checkVideoEnded();
1139
+ };
1140
+ /**
1068
1141
  * 获取当前视频时长
1069
1142
  */ _proto.getDuration = function getDuration() {
1070
1143
  return this.video ? this.video.duration : 0;
@@ -1513,7 +1586,7 @@ AudioComponent = __decorate([
1513
1586
 
1514
1587
  /**
1515
1588
  * 插件版本号
1516
- */ var version = "2.9.0";
1589
+ */ var version = "2.9.1-beta.0";
1517
1590
  registerPlugin("video", VideoLoader);
1518
1591
  registerPlugin("audio", AudioLoader);
1519
1592
  logger.info("Plugin multimedia version: " + version + ".");