Files
junisaber/src/components/song-progress-ring.js

36 lines
839 B
JavaScript
Raw Normal View History

2018-10-25 05:10:05 -07:00
AFRAME.registerComponent('song-progress-ring', {
dependencies: ['geometry', 'material'],
schema: {
enabled: {default: false}
},
init: function () {
this.tick = AFRAME.utils.throttleTick(this.tick.bind(this), 1000);
this.progress = this.el.getObject3D('mesh').material.uniforms.progress;
2018-10-25 05:10:05 -07:00
this.el.sceneEl.addEventListener('cleargame', () => {
this.progress.value = 0;
});
},
update: function (oldData) {
this.progress.value = 0;
2018-10-25 05:10:05 -07:00
},
updateRing: function () {
2018-10-25 05:10:05 -07:00
const source = this.el.sceneEl.components.song.source;
if (!source) { return; }
const progress =
this.el.sceneEl.components.song.getCurrentTime() /
source.buffer.duration;
2018-10-25 05:10:05 -07:00
this.progress.value = progress;
},
tick: function () {
if (!this.data.enabled) { return; }
this.updateRing();
2018-10-25 05:10:05 -07:00
}
});