@galacean/effects-plugin-multimedia 2.7.0-alpha.2 → 2.7.0-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.
@@ -1,8 +1,5 @@
1
1
  import { RendererComponent, spec } from '@galacean/effects';
2
2
  import { AudioPlayer } from './audio-player';
3
- /**
4
- * Audio component class
5
- */
6
3
  export declare class AudioComponent extends RendererComponent {
7
4
  audioPlayer: AudioPlayer;
8
5
  private isPlaying;
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.7.0-alpha.2
6
+ * Version: v2.7.0-beta.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -507,11 +507,11 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
507
507
  function VideoComponent(engine) {
508
508
  var _this;
509
509
  _this = MaskableGraphic.call(this, engine) || this;
510
- _this.threshold = 0.03;
511
510
  /**
512
511
  * 播放标志位
513
512
  */ _this.played = false;
514
513
  _this.pendingPause = false;
514
+ _this.threshold = 0.03;
515
515
  /**
516
516
  * 解决 video 暂停报错问题
517
517
  *
@@ -581,7 +581,7 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
581
581
  };
582
582
  _proto.onAwake = function onAwake() {
583
583
  var _this = this;
584
- var _this_item_composition, _this_item_composition1;
584
+ var _this_item_composition, _this_item_composition1, _this_item_composition2;
585
585
  MaskableGraphic.prototype.onAwake.call(this);
586
586
  (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.on("goto", function(option) {
587
587
  _this.setCurrentTime(_this.item.time);
@@ -589,6 +589,12 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
589
589
  (_this_item_composition1 = this.item.composition) == null ? void 0 : _this_item_composition1.on("pause", function() {
590
590
  _this.pauseVideo();
591
591
  });
592
+ (_this_item_composition2 = this.item.composition) == null ? void 0 : _this_item_composition2.on("play", function(option) {
593
+ if (_this.item.time < 0) {
594
+ return;
595
+ }
596
+ _this.playVideo();
597
+ });
592
598
  };
593
599
  _proto.fromData = function fromData(data) {
594
600
  MaskableGraphic.prototype.fromData.call(this, data);
@@ -629,32 +635,39 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
629
635
  };
630
636
  _proto.onUpdate = function onUpdate(dt) {
631
637
  MaskableGraphic.prototype.onUpdate.call(this, dt);
632
- var _this_item = this.item, time = _this_item.time, duration = _this_item.duration, endBehavior = _this_item.endBehavior, composition = _this_item.composition;
638
+ var _this_item = this.item, videoTime = _this_item.time, videoDuration = _this_item.duration, videoEndBehavior = _this_item.endBehavior, composition = _this_item.composition;
633
639
  EFFECTS.assertExist(composition);
634
640
  var _composition_rootItem = composition.rootItem, rootEndBehavior = _composition_rootItem.endBehavior, rootDuration = _composition_rootItem.duration;
635
- var isEnd = time === 0 || time === rootDuration || Math.abs(rootDuration - duration - time) < 1e-10 || Math.abs(time - duration) < this.threshold;
636
- if (time > 0 && !isEnd) {
637
- this.setVisible(true);
641
+ // 判断是否处于“结束状态”:
642
+ // - 视频时间为 0(未开始)
643
+ // - 合成时间已达最大时长(播放完毕)
644
+ // - 视频时间接近或等于其总时长(考虑容差阈值)
645
+ var isEnd = videoTime === 0 || composition.time === rootDuration || Math.abs(videoTime - videoDuration) <= this.threshold;
646
+ // 如果视频时间大于 0,且未到结束状态,并且尚未触发播放,则开始播放视频
647
+ if (videoTime > 0 && !isEnd && !this.played) {
638
648
  this.playVideo();
639
649
  }
640
- this.renderer.texture.uploadCurrentVideoFrame();
641
- if (time === 0 || time === rootDuration || Math.abs(rootDuration - duration - time) < 1e-10) {
642
- if (rootEndBehavior === EFFECTS.spec.EndBehavior.freeze) {
650
+ // 当视频播放时间接近或超过其总时长时,根据其结束行为进行处理
651
+ if (videoTime + this.threshold >= videoDuration) {
652
+ if (videoEndBehavior === EFFECTS.spec.EndBehavior.freeze) {
643
653
  var _this_video;
644
654
  if (!((_this_video = this.video) == null ? void 0 : _this_video.paused)) {
645
655
  this.pauseVideo();
646
- this.setCurrentTime(time);
647
656
  }
648
- } else {
649
- this.setCurrentTime(time);
657
+ } else if (videoEndBehavior === EFFECTS.spec.EndBehavior.destroy || videoEndBehavior === EFFECTS.spec.EndBehavior.restart) {
658
+ // 销毁由Composition管理,此处仅重置时间
659
+ this.setCurrentTime(0);
650
660
  }
651
661
  }
652
- if (Math.abs(time - duration) < this.threshold) {
653
- if (endBehavior === EFFECTS.spec.EndBehavior.freeze) {
654
- this.pauseVideo();
655
- } else if (endBehavior === EFFECTS.spec.EndBehavior.restart) {
656
- // 重播
657
- this.pauseVideo();
662
+ // 判断整个合成是否接近播放完成
663
+ // composition.time + threshold >= rootDuration 表示即将结束
664
+ if (composition.time + this.threshold >= rootDuration) {
665
+ if (rootEndBehavior === EFFECTS.spec.EndBehavior.freeze) {
666
+ var _this_video1;
667
+ if (!((_this_video1 = this.video) == null ? void 0 : _this_video1.paused)) {
668
+ this.pauseVideo();
669
+ }
670
+ } else if (rootEndBehavior === EFFECTS.spec.EndBehavior.restart) {
658
671
  this.setCurrentTime(0);
659
672
  }
660
673
  }
@@ -672,12 +685,6 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
672
685
  return this.video ? this.video.currentTime : 0;
673
686
  };
674
687
  /**
675
- * 设置阈值(由于视频是单独的 update,有时并不能完全对其 GE 的 update)
676
- * @param threshold 阈值
677
- */ _proto.setThreshold = function setThreshold(threshold) {
678
- this.threshold = threshold;
679
- };
680
- /**
681
688
  * 设置当前视频播放时刻
682
689
  * @param time 视频播放时刻
683
690
  */ _proto.setCurrentTime = function setCurrentTime(time) {
@@ -778,14 +785,9 @@ exports.VideoComponent = /*#__PURE__*/ function(MaskableGraphic) {
778
785
  }
779
786
  };
780
787
  _proto.onDisable = function onDisable() {
781
- var _this_item;
782
788
  MaskableGraphic.prototype.onDisable.call(this);
783
789
  this.isVideoActive = false;
784
790
  this.pauseVideo();
785
- var endBehavior = (_this_item = this.item) == null ? void 0 : _this_item.endBehavior;
786
- if (endBehavior === EFFECTS.spec.EndBehavior.restart) {
787
- this.setCurrentTime(0);
788
- }
789
791
  };
790
792
  _proto.onEnable = function onEnable() {
791
793
  MaskableGraphic.prototype.onEnable.call(this);
@@ -1041,6 +1043,7 @@ exports.AudioComponent = /*#__PURE__*/ function(RendererComponent) {
1041
1043
  var _this_item_composition, _this_item_composition1, _this_item_composition2;
1042
1044
  RendererComponent.prototype.onAwake.call(this);
1043
1045
  (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.on("play", function(option) {
1046
+ _this.audioPlayer.setMuted(false);
1044
1047
  if (_this.item.time <= 0) {
1045
1048
  return;
1046
1049
  }
@@ -1049,10 +1052,12 @@ exports.AudioComponent = /*#__PURE__*/ function(RendererComponent) {
1049
1052
  _this.isPlaying = true;
1050
1053
  });
1051
1054
  (_this_item_composition1 = this.item.composition) == null ? void 0 : _this_item_composition1.on("pause", function() {
1055
+ _this.audioPlayer.setMuted(true);
1052
1056
  _this.audioPlayer.pause();
1053
1057
  _this.isPlaying = false;
1054
1058
  });
1055
1059
  (_this_item_composition2 = this.item.composition) == null ? void 0 : _this_item_composition2.on("goto", function(option) {
1060
+ _this.audioPlayer.setMuted(true);
1056
1061
  _this.audioPlayer.setCurrentTime(_this.item.time);
1057
1062
  });
1058
1063
  };
@@ -1134,7 +1139,7 @@ exports.AudioComponent = __decorate([
1134
1139
 
1135
1140
  /**
1136
1141
  * 插件版本号
1137
- */ var version = "2.7.0-alpha.2";
1142
+ */ var version = "2.7.0-beta.0";
1138
1143
  EFFECTS.registerPlugin("video", VideoLoader, EFFECTS.VFXItem);
1139
1144
  EFFECTS.registerPlugin("audio", AudioLoader, EFFECTS.VFXItem);
1140
1145
  EFFECTS.logger.info("Plugin multimedia version: " + version + ".");