@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.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.9.0
6
+ * Version: v2.9.1-beta.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -768,10 +768,14 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
768
768
  _proto.onDisable = function onDisable() {
769
769
  MaskableGraphic.prototype.onDisable.call(this);
770
770
  this.isVideoActive = false;
771
+ this.playTriggered = false;
772
+ this.pauseVideoElement();
771
773
  };
772
774
  _proto.onEnable = function onEnable() {
773
775
  MaskableGraphic.prototype.onEnable.call(this);
774
776
  this.isVideoActive = true;
777
+ this.playTriggered = false;
778
+ this.syncVideoToItemTime();
775
779
  };
776
780
  /**
777
781
  * 处理 goto 事件:重置播放状态,记录待 seek 时间
@@ -780,7 +784,7 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
780
784
  this.isWaitingForGotoResult = true;
781
785
  this.playTriggered = false;
782
786
  this.manualPause = false;
783
- this.pendingSeekTime = this.item.time;
787
+ this.pendingSeekTime = this.getItemSeekTime();
784
788
  };
785
789
  /**
786
790
  * 处理合成 pause 事件
@@ -791,7 +795,7 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
791
795
  this.isWaitingForGotoResult = false;
792
796
  if (this.video && this.video.readyState >= 2) {
793
797
  this.isGotoAndStopSeeking = true;
794
- this.performSeek(this.item.time, false, true);
798
+ this.performSeek(this.getItemSeekTime(), false, true);
795
799
  }
796
800
  return;
797
801
  }
@@ -809,7 +813,7 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
809
813
  if (!this.checkCompositionEnded()) {
810
814
  var _this_video;
811
815
  // 如果正在 seeking,不恢复播放,等 seek 完成后再恢复
812
- if (!this.manualPause && !this.videoSeeking && ((_this_video = this.video) == null ? void 0 : _this_video.paused)) {
816
+ if (this.canPlayCurrentItem() && ((_this_video = this.video) == null ? void 0 : _this_video.paused)) {
813
817
  this.safePlay();
814
818
  }
815
819
  return;
@@ -882,14 +886,10 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
882
886
  /**
883
887
  * 是否应该启动视频播放
884
888
  */ _proto.shouldStartVideo = function shouldStartVideo() {
885
- if (this.playTriggered || this.manualPause || this.videoDestroyed || this.checkVideoEnded()) {
886
- return false;
887
- }
888
- var composition = this.item.composition;
889
- if (!composition) {
889
+ if (this.playTriggered || !this.canPlayCurrentItem()) {
890
890
  return false;
891
891
  }
892
- return this.video.currentTime > 0 || composition.time > 0;
892
+ return true;
893
893
  };
894
894
  /**
895
895
  * 处理延迟 seek,返回 true 表示本帧已处理 seek,应跳过后续逻辑
@@ -1020,8 +1020,25 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
1020
1020
  var _this = this;
1021
1021
  if (clearTexture === void 0) clearTexture = false;
1022
1022
  if (isGotoAndStop === void 0) isGotoAndStop = false;
1023
+ time = this.getClampedSeekTime(time);
1023
1024
  var wasPlaying = !this.video.paused;
1025
+ var isNoopSeek = function() {
1026
+ return !clearTexture && Math.abs(_this.video.currentTime - time) <= VideoComponent.threshold;
1027
+ };
1028
+ var finishNoopSeek = function() {
1029
+ _this.videoSeeking = false;
1030
+ _this.isGotoAndStopSeeking = false;
1031
+ if (isGotoAndStop) {
1032
+ _this.video.pause();
1033
+ } else if (wasPlaying && !_this.manualPause) {
1034
+ _this.safePlay();
1035
+ }
1036
+ };
1024
1037
  var doSeek = function() {
1038
+ if (isNoopSeek()) {
1039
+ finishNoopSeek();
1040
+ return;
1041
+ }
1025
1042
  _this.videoSeeking = true;
1026
1043
  if (clearTexture) {
1027
1044
  _this.material.setTexture("_MainTex", _this.engine.transparentTexture);
@@ -1051,6 +1068,8 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
1051
1068
  if (wasPlaying) {
1052
1069
  // 视频正在播放,直接 seek
1053
1070
  doSeek();
1071
+ } else if (isNoopSeek()) {
1072
+ finishNoopSeek();
1054
1073
  } else {
1055
1074
  // 视频暂停,先 play() 再 seek
1056
1075
  this.video.play().then(function() {
@@ -1088,6 +1107,60 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
1088
1107
  }
1089
1108
  };
1090
1109
  /**
1110
+ * 当前 item 可播放的本地视频时间。
1111
+ * item.time 在 delay 前为负数,视频时间需要从 0 开始。
1112
+ */ _proto.getItemSeekTime = function getItemSeekTime() {
1113
+ return Math.max(0, this.getItemLocalTime());
1114
+ };
1115
+ /**
1116
+ * 获取 item 的本地时间。优先使用 timeline 写入的 item.time,
1117
+ * 未写入时使用合成时间和 item delay 做兜底。
1118
+ */ _proto.getItemLocalTime = function getItemLocalTime() {
1119
+ if (this.item.time >= 0) {
1120
+ return this.item.time;
1121
+ }
1122
+ var composition = this.item.composition;
1123
+ if (!composition) {
1124
+ return this.item.time;
1125
+ }
1126
+ var _this_item_definition_delay;
1127
+ return composition.time - ((_this_item_definition_delay = this.item.definition.delay) != null ? _this_item_definition_delay : 0);
1128
+ };
1129
+ /**
1130
+ * 将 seek 目标限制到视频有效时间范围内。
1131
+ */ _proto.getClampedSeekTime = function getClampedSeekTime(time) {
1132
+ var _this_video;
1133
+ var seekTime = Math.max(0, time);
1134
+ var duration = (_this_video = this.video) == null ? void 0 : _this_video.duration;
1135
+ if (!duration || !isFinite(duration)) {
1136
+ return seekTime;
1137
+ }
1138
+ return Math.min(seekTime, duration);
1139
+ };
1140
+ /**
1141
+ * 组件重新启用时将视频时间对齐到 item 本地时间,但不直接触发播放。
1142
+ */ _proto.syncVideoToItemTime = function syncVideoToItemTime() {
1143
+ if (!this.video) {
1144
+ return;
1145
+ }
1146
+ var seekTime = this.getItemSeekTime();
1147
+ var clampedSeekTime = this.getClampedSeekTime(seekTime);
1148
+ if (Math.abs(this.video.currentTime - clampedSeekTime) > VideoComponent.threshold) {
1149
+ this.pendingSeekTime = clampedSeekTime;
1150
+ }
1151
+ };
1152
+ /**
1153
+ * 当前 item 已经进入自己的时间区间,且视频允许自动播放。
1154
+ */ _proto.canPlayCurrentItem = function canPlayCurrentItem() {
1155
+ if (!this.video || !this.isVideoActive || this.getItemLocalTime() < 0) {
1156
+ return false;
1157
+ }
1158
+ if (this.manualPause || this.videoDestroyed || this.videoSeeking || this.pendingSeekTime !== null) {
1159
+ return false;
1160
+ }
1161
+ return !this.checkVideoEnded();
1162
+ };
1163
+ /**
1091
1164
  * 获取当前视频时长
1092
1165
  */ _proto.getDuration = function getDuration() {
1093
1166
  return this.video ? this.video.duration : 0;
@@ -1536,7 +1609,7 @@ exports.AudioComponent = __decorate([
1536
1609
 
1537
1610
  /**
1538
1611
  * 插件版本号
1539
- */ var version = "2.9.0";
1612
+ */ var version = "2.9.1-beta.0";
1540
1613
  EFFECTS.registerPlugin("video", VideoLoader);
1541
1614
  EFFECTS.registerPlugin("audio", AudioLoader);
1542
1615
  EFFECTS.logger.info("Plugin multimedia version: " + version + ".");