@galacean/effects-plugin-multimedia 2.2.6 → 2.3.0-alpha.1
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 +137 -36
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +138 -37
- package/dist/index.mjs.map +1 -1
- package/dist/video/video-component.d.ts +31 -6
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* Description: Galacean Effects player multimedia plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 云垣
|
|
6
|
-
* Version: v2.
|
|
6
|
+
* Version: v2.3.0-alpha.1
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
10
|
-
import { isFunction, passRenderLevel, spec, loadVideo, loadBinary, AbstractPlugin, effectsClass, glContext, getImageItemRenderInfo, math, BaseRenderComponent, RendererComponent, registerPlugin, VFXItem, logger } from '@galacean/effects';
|
|
10
|
+
import { isFunction, passRenderLevel, spec, loadVideo, loadBinary, AbstractPlugin, effectsClass, glContext, PLAYER_OPTIONS_ENV_EDITOR, GLSLVersion, getImageItemRenderInfo, math, assertExist, BaseRenderComponent, itemFrag, itemVert, Texture, RendererComponent, registerPlugin, VFXItem, logger } from '@galacean/effects';
|
|
11
11
|
|
|
12
12
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
13
13
|
try {
|
|
@@ -485,26 +485,111 @@ var VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
|
|
|
485
485
|
var _this;
|
|
486
486
|
_this = BaseRenderComponent.call(this, engine) || this;
|
|
487
487
|
_this.threshold = 0.03;
|
|
488
|
+
/**
|
|
489
|
+
* 播放标志位
|
|
490
|
+
*/ _this.played = false;
|
|
491
|
+
/**
|
|
492
|
+
* 视频元素是否激活
|
|
493
|
+
*/ _this.isVideoActive = false;
|
|
494
|
+
/**
|
|
495
|
+
* 是否为透明视频
|
|
496
|
+
*/ _this.transparent = false;
|
|
488
497
|
_this.name = "MVideo" + seed++;
|
|
489
498
|
_this.geometry = _this.createGeometry(glContext.TRIANGLES);
|
|
490
499
|
return _this;
|
|
491
500
|
}
|
|
492
501
|
var _proto = VideoComponent.prototype;
|
|
493
|
-
_proto.setTexture = function setTexture(
|
|
494
|
-
var
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
+
_proto.setTexture = function setTexture(input) {
|
|
503
|
+
var _this = this;
|
|
504
|
+
return _async_to_generator(function() {
|
|
505
|
+
var oldTexture, composition, texture;
|
|
506
|
+
return __generator(this, function(_state) {
|
|
507
|
+
switch(_state.label){
|
|
508
|
+
case 0:
|
|
509
|
+
oldTexture = _this.renderer.texture;
|
|
510
|
+
composition = _this.item.composition;
|
|
511
|
+
if (!(typeof input === "string")) return [
|
|
512
|
+
3,
|
|
513
|
+
2
|
|
514
|
+
];
|
|
515
|
+
return [
|
|
516
|
+
4,
|
|
517
|
+
Texture.fromVideo(input, _this.item.engine)
|
|
518
|
+
];
|
|
519
|
+
case 1:
|
|
520
|
+
texture = _state.sent();
|
|
521
|
+
return [
|
|
522
|
+
3,
|
|
523
|
+
3
|
|
524
|
+
];
|
|
525
|
+
case 2:
|
|
526
|
+
texture = input;
|
|
527
|
+
_state.label = 3;
|
|
528
|
+
case 3:
|
|
529
|
+
if (!composition) {
|
|
530
|
+
return [
|
|
531
|
+
2
|
|
532
|
+
];
|
|
533
|
+
}
|
|
534
|
+
composition.textures.forEach(function(cachedTexture, index) {
|
|
535
|
+
if (cachedTexture === oldTexture) {
|
|
536
|
+
composition.textures[index] = texture;
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
_this.engine.removeTexture(oldTexture);
|
|
540
|
+
_this.renderer.texture = texture;
|
|
541
|
+
_this.material.setTexture("_MainTex", texture);
|
|
542
|
+
_this.video = texture.source.video;
|
|
543
|
+
return [
|
|
544
|
+
2
|
|
545
|
+
];
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
})();
|
|
549
|
+
};
|
|
550
|
+
_proto.onAwake = function onAwake() {
|
|
551
|
+
var _this = this;
|
|
552
|
+
var _this_item_composition;
|
|
553
|
+
BaseRenderComponent.prototype.onAwake.call(this);
|
|
554
|
+
(_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.on("goto", function(option) {
|
|
555
|
+
if (option.time > 0) {
|
|
556
|
+
var _this_item = _this.item, endBehavior = _this_item.endBehavior, start = _this_item.start, duration = _this_item.duration;
|
|
557
|
+
if (endBehavior === spec.EndBehavior.freeze || endBehavior === spec.EndBehavior.restart) {
|
|
558
|
+
_this.setCurrentTime((option.time - start) % duration);
|
|
559
|
+
} else {
|
|
560
|
+
if (option.time >= duration) {
|
|
561
|
+
_this.onDisable();
|
|
562
|
+
} else {
|
|
563
|
+
_this.setCurrentTime(option.time - start);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
502
566
|
}
|
|
503
567
|
});
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
568
|
+
};
|
|
569
|
+
_proto.getMaterialProps = function getMaterialProps(renderInfo, count) {
|
|
570
|
+
var _this_engine_renderer;
|
|
571
|
+
var macros = [
|
|
572
|
+
[
|
|
573
|
+
"TRANSPARENT_VIDEO",
|
|
574
|
+
this.transparent
|
|
575
|
+
],
|
|
576
|
+
[
|
|
577
|
+
"ENV_EDITOR",
|
|
578
|
+
((_this_engine_renderer = this.engine.renderer) == null ? void 0 : _this_engine_renderer.env) === PLAYER_OPTIONS_ENV_EDITOR
|
|
579
|
+
]
|
|
580
|
+
];
|
|
581
|
+
var fragment = itemFrag;
|
|
582
|
+
var vertex = itemVert;
|
|
583
|
+
var shader = {
|
|
584
|
+
fragment: fragment,
|
|
585
|
+
vertex: vertex,
|
|
586
|
+
glslVersion: count === 1 ? GLSLVersion.GLSL1 : GLSLVersion.GLSL3,
|
|
587
|
+
macros: macros,
|
|
588
|
+
shared: true
|
|
589
|
+
};
|
|
590
|
+
return {
|
|
591
|
+
shader: shader
|
|
592
|
+
};
|
|
508
593
|
};
|
|
509
594
|
_proto.fromData = function fromData(data) {
|
|
510
595
|
BaseRenderComponent.prototype.fromData.call(this, data);
|
|
@@ -514,8 +599,9 @@ var VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
|
|
|
514
599
|
1,
|
|
515
600
|
1,
|
|
516
601
|
1
|
|
517
|
-
] : _options_startColor, _options_playbackRate = options.playbackRate, playbackRate = _options_playbackRate === void 0 ? 1 : _options_playbackRate, _options_volume = options.volume, volume = _options_volume === void 0 ? 1 : _options_volume, _options_muted = options.muted, muted = _options_muted === void 0 ? false : _options_muted;
|
|
602
|
+
] : _options_startColor, _options_playbackRate = options.playbackRate, playbackRate = _options_playbackRate === void 0 ? 1 : _options_playbackRate, _options_volume = options.volume, volume = _options_volume === void 0 ? 1 : _options_volume, _options_muted = options.muted, muted = _options_muted === void 0 ? false : _options_muted, _options_transparent = options.transparent, transparent = _options_transparent === void 0 ? false : _options_transparent;
|
|
518
603
|
var renderer = data.renderer;
|
|
604
|
+
this.transparent = transparent;
|
|
519
605
|
if (!renderer) {
|
|
520
606
|
renderer = {};
|
|
521
607
|
}
|
|
@@ -524,7 +610,7 @@ var VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
|
|
|
524
610
|
this.setPlaybackRate(playbackRate);
|
|
525
611
|
this.setVolume(volume);
|
|
526
612
|
this.setMuted(muted);
|
|
527
|
-
var endBehavior = this.item.endBehavior;
|
|
613
|
+
var endBehavior = this.item.taggedProperties.endBehavior;
|
|
528
614
|
// 如果元素设置为 destroy
|
|
529
615
|
if (endBehavior === spec.EndBehavior.destroy) {
|
|
530
616
|
this.setLoop(false);
|
|
@@ -548,6 +634,9 @@ var VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
|
|
|
548
634
|
this.renderInfo = getImageItemRenderInfo(this);
|
|
549
635
|
var geometry = this.createGeometry(glContext.TRIANGLES);
|
|
550
636
|
var material = this.createMaterial(this.renderInfo, 2);
|
|
637
|
+
if (this.transparent) {
|
|
638
|
+
this.material.enableMacro("TRANSPARENT_VIDEO", this.transparent);
|
|
639
|
+
}
|
|
551
640
|
this.worldMatrix = math.Matrix4.fromIdentity();
|
|
552
641
|
this.material = material;
|
|
553
642
|
this.geometry = geometry;
|
|
@@ -560,27 +649,25 @@ var VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
|
|
|
560
649
|
]));
|
|
561
650
|
this.setItem();
|
|
562
651
|
};
|
|
563
|
-
_proto.onStart = function onStart() {
|
|
564
|
-
var _this = this;
|
|
565
|
-
var _this_item_composition;
|
|
566
|
-
BaseRenderComponent.prototype.onStart.call(this);
|
|
567
|
-
(_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.on("goto", function(option) {
|
|
568
|
-
if (option.time > 0) {
|
|
569
|
-
_this.setCurrentTime(option.time);
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
};
|
|
573
652
|
_proto.onUpdate = function onUpdate(dt) {
|
|
574
|
-
var _this_item_composition;
|
|
575
653
|
BaseRenderComponent.prototype.onUpdate.call(this, dt);
|
|
576
|
-
var _this_item = this.item, time = _this_item.time, duration = _this_item.duration, endBehavior = _this_item.endBehavior;
|
|
654
|
+
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;
|
|
655
|
+
assertExist(composition);
|
|
656
|
+
var _composition_rootItem = composition.rootItem, rootEndBehavior = _composition_rootItem.endBehavior, rootDuration = _composition_rootItem.duration;
|
|
577
657
|
if (time > 0) {
|
|
578
658
|
this.setVisible(true);
|
|
579
659
|
this.playVideo();
|
|
580
660
|
}
|
|
581
|
-
if (time === 0
|
|
582
|
-
|
|
583
|
-
|
|
661
|
+
if (time === 0 || time === rootDuration - start || Math.abs(rootDuration - duration - time) < 1e-10) {
|
|
662
|
+
if (rootEndBehavior === spec.EndBehavior.freeze) {
|
|
663
|
+
var _this_video;
|
|
664
|
+
if (!((_this_video = this.video) == null ? void 0 : _this_video.paused)) {
|
|
665
|
+
this.pauseVideo();
|
|
666
|
+
this.setCurrentTime(time);
|
|
667
|
+
}
|
|
668
|
+
} else {
|
|
669
|
+
this.setCurrentTime(time);
|
|
670
|
+
}
|
|
584
671
|
}
|
|
585
672
|
if (Math.abs(time - duration) < this.threshold) {
|
|
586
673
|
if (endBehavior === spec.EndBehavior.freeze) {
|
|
@@ -652,15 +739,28 @@ var VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
|
|
|
652
739
|
}
|
|
653
740
|
this.video.playbackRate = rate;
|
|
654
741
|
};
|
|
655
|
-
|
|
742
|
+
/**
|
|
743
|
+
* 播放视频
|
|
744
|
+
* @since 2.3.0
|
|
745
|
+
*/ _proto.playVideo = function playVideo() {
|
|
656
746
|
var _this = this;
|
|
747
|
+
if (this.played) {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
657
750
|
if (this.video) {
|
|
751
|
+
this.played = true;
|
|
658
752
|
this.video.play().catch(function(error) {
|
|
659
753
|
_this.engine.renderErrors.add(error);
|
|
660
754
|
});
|
|
661
755
|
}
|
|
662
756
|
};
|
|
663
|
-
|
|
757
|
+
/**
|
|
758
|
+
* 暂停视频
|
|
759
|
+
* @since 2.3.0
|
|
760
|
+
*/ _proto.pauseVideo = function pauseVideo() {
|
|
761
|
+
if (this.played) {
|
|
762
|
+
this.played = false;
|
|
763
|
+
}
|
|
664
764
|
if (this.video && !this.video.paused) {
|
|
665
765
|
this.video.pause();
|
|
666
766
|
}
|
|
@@ -674,13 +774,14 @@ var VideoComponent = /*#__PURE__*/ function(BaseRenderComponent) {
|
|
|
674
774
|
}
|
|
675
775
|
};
|
|
676
776
|
_proto.onDisable = function onDisable() {
|
|
677
|
-
var _this_video;
|
|
678
777
|
BaseRenderComponent.prototype.onDisable.call(this);
|
|
679
778
|
this.setCurrentTime(0);
|
|
680
|
-
|
|
779
|
+
this.isVideoActive = false;
|
|
780
|
+
this.pauseVideo();
|
|
681
781
|
};
|
|
682
782
|
_proto.onEnable = function onEnable() {
|
|
683
783
|
BaseRenderComponent.prototype.onEnable.call(this);
|
|
784
|
+
this.isVideoActive = true;
|
|
684
785
|
this.playVideo();
|
|
685
786
|
};
|
|
686
787
|
return VideoComponent;
|
|
@@ -950,7 +1051,7 @@ AudioComponent = __decorate([
|
|
|
950
1051
|
|
|
951
1052
|
/**
|
|
952
1053
|
* 插件版本号
|
|
953
|
-
*/ var version = "2.
|
|
1054
|
+
*/ var version = "2.3.0-alpha.1";
|
|
954
1055
|
registerPlugin("video", VideoLoader, VFXItem, true);
|
|
955
1056
|
registerPlugin("audio", AudioLoader, VFXItem, true);
|
|
956
1057
|
logger.info("Plugin multimedia version: " + version + ".");
|