javascript - AFrame:视频(视频球)结束时如何显示按钮?
问题描述
我正在尝试检测 mp4 格式的 360 视频是否在显示隐藏的 btn1 之前结束。
<a-videosphere id="videosphere1"
rotation="0 180 0"
visible="true"
src="#vid1"
show-btn-when-ended="target: #btn1"
autoplay = "true">
</a-videosphere>
要显示的按钮
<a-entity
id="btn1"
geometry = "primative: plane"
position = "-0.8 3 -12.3"
rotation = "0 -1 -3"
scale = "12.5 25 1"
visible = "false"
text = "align:center; width: 6; wrapCount:100; color:black;
value: CLICK HERE"
go-toScene-onCLick>
</a-entity>
脚本不工作。无法使用 javascript 将可见属性更改为 true
AFRAME.registerComponent('show-btn-when-ended', {
init: function () {
el = this.el;
this.showBtn= this.showBtn.bind(this);
el.addEventListener('ended', this.showBtn);
},
showBtn: function(evt) {
console.log('in window.showBtn');
var videosphere1 = document.querySelector("#videosphere1")
var btn1 = document.querySelector('#btn1');
btn1.setAttribute('visible', 'true');
console.log("Show Button");
}
})
解决方案
根据 A-Frame 文档,您应该能够materialvideoended
在原语上监听事件<a-videosphere>
。
https://aframe.io/docs/0.8.0/components/material.html#events_materialvideoended
所以你应该能够做这样的事情:
videosphere1.addEventListener('materialvideoended', function() {
// show button
});
我注意到您最初试图target
通过组件传递按钮的选择器。您可以通过执行以下操作将其添加到组件的架构中来做到这一点:
schema: {
target: { type: 'selector', default: '[a-videosphere]' }
}
如果没有定义选择器,它将默认为第一个<a-videosphere>
原语。
推荐阅读
- google-bigquery - 使用 Big Query 将 firebase event_params 键值数据显示到单行中
- wpf - WPF中从中心点到特定点的路径,ArcSegment计算
- java - 错误:在 PI 上运行 Arduino IDE 时,线程“main”java.lang.NullPointerException 出现异常
- json - PowerShell - 遍历 JSON
- javascript - NVD3 工具提示更改事件
- php - Symfony 注入一个字符串而不是服务
- java - 内部类的 NPE
- c# - Moq 在使用 It.Is 但不是 It.IsAny 进行验证时抛出 NullReferenceException
- python - 如何检查列表中的连续时间戳
- javascript - 如何在不使用 PaperScript 的情况下平移 PaperJS