@galacean/effects-plugin-multimedia 2.2.6 → 2.3.0-alpha.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.2.6
6
+ * Version: v2.3.0-alpha.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -508,26 +508,83 @@ exports.VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
508
508
  var _this;
509
509
  _this = BaseRenderComponent.call(this, engine) || this;
510
510
  _this.threshold = 0.03;
511
+ /**
512
+ * 播放标志位
513
+ */ _this.played = false;
514
+ /**
515
+ * 视频元素是否激活
516
+ */ _this.isVideoActive = false;
511
517
  _this.name = "MVideo" + seed++;
512
518
  _this.geometry = _this.createGeometry(EFFECTS.glContext.TRIANGLES);
513
519
  return _this;
514
520
  }
515
521
  var _proto = VideoComponent.prototype;
516
- _proto.setTexture = function setTexture(texture) {
517
- var oldTexture = this.renderer.texture;
518
- var composition = this.item.composition;
519
- if (!composition) {
520
- return;
521
- }
522
- composition.textures.forEach(function(cachedTexture, index) {
523
- if (cachedTexture === oldTexture) {
524
- composition.textures[index] = texture;
522
+ _proto.setTexture = function setTexture(input) {
523
+ var _this = this;
524
+ return _async_to_generator(function() {
525
+ var oldTexture, composition, texture;
526
+ return __generator(this, function(_state) {
527
+ switch(_state.label){
528
+ case 0:
529
+ oldTexture = _this.renderer.texture;
530
+ composition = _this.item.composition;
531
+ if (!(typeof input === "string")) return [
532
+ 3,
533
+ 2
534
+ ];
535
+ return [
536
+ 4,
537
+ EFFECTS.Texture.fromVideo(input, _this.item.engine)
538
+ ];
539
+ case 1:
540
+ texture = _state.sent();
541
+ return [
542
+ 3,
543
+ 3
544
+ ];
545
+ case 2:
546
+ texture = input;
547
+ _state.label = 3;
548
+ case 3:
549
+ if (!composition) {
550
+ return [
551
+ 2
552
+ ];
553
+ }
554
+ composition.textures.forEach(function(cachedTexture, index) {
555
+ if (cachedTexture === oldTexture) {
556
+ composition.textures[index] = texture;
557
+ }
558
+ });
559
+ _this.engine.removeTexture(oldTexture);
560
+ _this.renderer.texture = texture;
561
+ _this.material.setTexture("_MainTex", texture);
562
+ _this.video = texture.source.video;
563
+ return [
564
+ 2
565
+ ];
566
+ }
567
+ });
568
+ })();
569
+ };
570
+ _proto.onAwake = function onAwake() {
571
+ var _this = this;
572
+ var _this_item_composition;
573
+ BaseRenderComponent.prototype.onAwake.call(this);
574
+ (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.on("goto", function(option) {
575
+ if (option.time > 0) {
576
+ var _this_item = _this.item, endBehavior = _this_item.endBehavior, start = _this_item.start, duration = _this_item.duration;
577
+ if (endBehavior === EFFECTS.spec.EndBehavior.freeze || endBehavior === EFFECTS.spec.EndBehavior.restart) {
578
+ _this.setCurrentTime((option.time - start) % duration);
579
+ } else {
580
+ if (option.time >= duration) {
581
+ _this.onDisable();
582
+ } else {
583
+ _this.setCurrentTime(option.time - start);
584
+ }
585
+ }
525
586
  }
526
587
  });
527
- this.engine.removeTexture(oldTexture);
528
- this.renderer.texture = texture;
529
- this.material.setTexture("_MainTex", texture);
530
- this.video = texture.source.video;
531
588
  };
532
589
  _proto.fromData = function fromData(data) {
533
590
  BaseRenderComponent.prototype.fromData.call(this, data);
@@ -547,7 +604,7 @@ exports.VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
547
604
  this.setPlaybackRate(playbackRate);
548
605
  this.setVolume(volume);
549
606
  this.setMuted(muted);
550
- var endBehavior = this.item.endBehavior;
607
+ var endBehavior = this.item.taggedProperties.endBehavior;
551
608
  // 如果元素设置为 destroy
552
609
  if (endBehavior === EFFECTS.spec.EndBehavior.destroy) {
553
610
  this.setLoop(false);
@@ -583,27 +640,25 @@ exports.VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
583
640
  ]));
584
641
  this.setItem();
585
642
  };
586
- _proto.onStart = function onStart() {
587
- var _this = this;
588
- var _this_item_composition;
589
- BaseRenderComponent.prototype.onStart.call(this);
590
- (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.on("goto", function(option) {
591
- if (option.time > 0) {
592
- _this.setCurrentTime(option.time);
593
- }
594
- });
595
- };
596
643
  _proto.onUpdate = function onUpdate(dt) {
597
- var _this_item_composition;
598
644
  BaseRenderComponent.prototype.onUpdate.call(this, dt);
599
- var _this_item = this.item, time = _this_item.time, duration = _this_item.duration, endBehavior = _this_item.endBehavior;
645
+ var _this_item = this.item, time = _this_item.time, duration = _this_item.duration, endBehavior = _this_item.endBehavior, composition = _this_item.composition, start = _this_item.start;
646
+ EFFECTS.assertExist(composition);
647
+ var _composition_rootItem = composition.rootItem, rootEndBehavior = _composition_rootItem.endBehavior, rootDuration = _composition_rootItem.duration;
600
648
  if (time > 0) {
601
649
  this.setVisible(true);
602
650
  this.playVideo();
603
651
  }
604
- if (time === 0 && ((_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.rootItem.endBehavior) === EFFECTS.spec.EndBehavior.freeze) {
605
- this.pauseVideo();
606
- this.setCurrentTime(0);
652
+ if (time === 0 || time === rootDuration - start) {
653
+ if (rootEndBehavior === EFFECTS.spec.EndBehavior.freeze) {
654
+ var _this_video;
655
+ if (!((_this_video = this.video) == null ? void 0 : _this_video.paused)) {
656
+ this.pauseVideo();
657
+ this.setCurrentTime(time);
658
+ }
659
+ } else {
660
+ this.setCurrentTime(time);
661
+ }
607
662
  }
608
663
  if (Math.abs(time - duration) < this.threshold) {
609
664
  if (endBehavior === EFFECTS.spec.EndBehavior.freeze) {
@@ -675,15 +730,28 @@ exports.VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
675
730
  }
676
731
  this.video.playbackRate = rate;
677
732
  };
678
- _proto.playVideo = function playVideo() {
733
+ /**
734
+ * 播放视频
735
+ * @since 2.3.0
736
+ */ _proto.playVideo = function playVideo() {
679
737
  var _this = this;
738
+ if (this.played) {
739
+ return;
740
+ }
680
741
  if (this.video) {
742
+ this.played = true;
681
743
  this.video.play().catch(function(error) {
682
744
  _this.engine.renderErrors.add(error);
683
745
  });
684
746
  }
685
747
  };
686
- _proto.pauseVideo = function pauseVideo() {
748
+ /**
749
+ * 暂停视频
750
+ * @since 2.3.0
751
+ */ _proto.pauseVideo = function pauseVideo() {
752
+ if (this.played) {
753
+ this.played = false;
754
+ }
687
755
  if (this.video && !this.video.paused) {
688
756
  this.video.pause();
689
757
  }
@@ -697,13 +765,14 @@ exports.VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
697
765
  }
698
766
  };
699
767
  _proto.onDisable = function onDisable() {
700
- var _this_video;
701
768
  BaseRenderComponent.prototype.onDisable.call(this);
702
769
  this.setCurrentTime(0);
703
- (_this_video = this.video) == null ? void 0 : _this_video.pause();
770
+ this.isVideoActive = false;
771
+ this.pauseVideo();
704
772
  };
705
773
  _proto.onEnable = function onEnable() {
706
774
  BaseRenderComponent.prototype.onEnable.call(this);
775
+ this.isVideoActive = true;
707
776
  this.playVideo();
708
777
  };
709
778
  return VideoComponent;
@@ -973,7 +1042,7 @@ exports.AudioComponent = __decorate([
973
1042
 
974
1043
  /**
975
1044
  * 插件版本号
976
- */ var version = "2.2.6";
1045
+ */ var version = "2.3.0-alpha.0";
977
1046
  EFFECTS.registerPlugin("video", VideoLoader, EFFECTS.VFXItem, true);
978
1047
  EFFECTS.registerPlugin("audio", AudioLoader, EFFECTS.VFXItem, true);
979
1048
  EFFECTS.logger.info("Plugin multimedia version: " + version + ".");