store song duration and length in state

This commit is contained in:
Kevin Ngo
2018-10-16 23:06:20 -07:00
parent 41a7bae85b
commit f0785650c5
3 changed files with 12 additions and 2 deletions

View File

@@ -97,6 +97,7 @@ AFRAME.registerComponent('beat-loader', {
*/
handleBeats: function (beatData) {
this.el.sceneEl.emit('beatloaderfinish', beatData, false);
// Reset variables used during playback.
// Beats spawn ahead of the song and get to the user in sync with the music.
this.beatsTimeOffset = this.data.beatAnticipationTime * 1000;

View File

@@ -177,6 +177,8 @@ AFRAME.registerComponent('song-preview-system', {
this.fadeIn();
this.updateAnalyser();
this.el.sceneEl.emit('menuselectedchallengesonglength', this.audio.duration, false);
// Prefetch buffer for playing.
if (audioanalyser.xhr) { audioanalyser.xhr.abort(); }
audioanalyser.fetchAudioBuffer(utils.getS3FileUrl(challengeId, 'song.ogg'));

View File

@@ -30,7 +30,8 @@ AFRAME.registerState({
isLoading: false,
isBeatsPreloaded: false,
songName: '',
songSubName: ''
songSubName: '',
songLength: 0
},
damage: 0,
inVR: false,
@@ -45,6 +46,7 @@ AFRAME.registerState({
menuDifficulties: [],
menuSelectedChallenge: {
author: '',
bpm: 0,
difficulty: '',
downloads: '',
downloadsText: '',
@@ -52,6 +54,7 @@ AFRAME.registerState({
index: -1,
image: '',
songName: '',
songLength: 0,
songSubName: ''
},
multiplierText: '1x',
@@ -111,7 +114,7 @@ AFRAME.registerState({
takeDamage(state);
},
beatloaderfinish: (state) => {
beatloaderfinish: (state, payload) => {
state.challenge.isLoading = false;
},
@@ -187,6 +190,10 @@ AFRAME.registerState({
state.menuSelectedChallenge.difficulty = difficulty;
},
menuselectedchallengesonglength: (state, seconds) => {
state.menuSelectedChallenge.songLength = seconds;
},
minehit: state => {
takeDamage(state);
},