Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
culdo committed Dec 27, 2024
1 parent 2e48d9d commit f5c9317
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 107 deletions.
78 changes: 0 additions & 78 deletions app/modules/MMDAnimationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,84 +1015,6 @@ function updateOne(mesh: THREE.SkinnedMesh, boneIndex: number, ikSolver: { updat

}

//

class AudioManager {
audio: any;
elapsedTime: number;
currentTime: number;
delayTime: any;
audioDuration: any;
duration: any;
elapsed: any;

/**
* @param {THREE.Audio} audio
* @param {Object} params - (optional)
* @param {Number} params.delayTime
*/
constructor(audio: any, params: { delayTime: number; } = {
delayTime: 0
}) {

this.audio = audio;

this.elapsedTime = 0.0;
this.currentTime = 0.0;
this.delayTime = params.delayTime !== undefined
? params.delayTime : 0.0;

this.audioDuration = this.audio.buffer.duration;
this.duration = this.audioDuration + this.delayTime;

}

/**
* @param {Number} delta
* @return {AudioManager}
*/
control(delta: number): AudioManager {

this.elapsed += delta;
this.currentTime += delta;

if (this._shouldStopAudio()) this.audio.stop();
if (this._shouldStartAudio()) this.audio.play();

return this;

}

// private methods

_shouldStartAudio() {

if (this.audio.isPlaying) return false;

while (this.currentTime >= this.duration) {

this.currentTime -= this.duration;

}

if (this.currentTime < this.delayTime) return false;

// 'duration' can be bigger than 'audioDuration + delayTime' because of sync configuration
if ((this.currentTime - this.delayTime) > this.audioDuration) return false;

return true;

}

_shouldStopAudio() {

return this.audio.isPlaying &&
this.currentTime >= this.duration;

}

}

const _q = new Quaternion();

/**
Expand Down
30 changes: 1 addition & 29 deletions app/utils/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,6 @@ function withProgress(resp: Response, totalSize: number) {
}));
}

let init = false
async function loadMusicFromYT(api: { currentTime: number; volume: number; musicYtURL: string }) {
const player = videojs.getPlayer("rawPlayer")
player.src({
"type": "video/youtube",
"src": api.musicYtURL
})

// workaroud for yt policy
if (!init) {
const savedTime = api["currentTime"]
const savedVolume = api["volume"]
await player.play()
player.volume(0.0);
player.on('play', async () => {
if (!init) {
player.pause()
player.currentTime(savedTime);
await player.play()
player.pause()
player.currentTime(savedTime);
player.volume(savedVolume);
init = true
}
})
}
}

function dataURItoBlobUrl(dataURI: string) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
Expand Down Expand Up @@ -161,4 +133,4 @@ function debugWait(ms = 2000) {
return new Promise((res) => setTimeout(() => res(true), ms))
}

export { blobToBase64, dataURItoBlobUrl, debugWait, disposeMesh, loadMusicFromYT, onProgress, saveCurrTime, startFileDownload, withProgress, withTimeElapse };
export { blobToBase64, dataURItoBlobUrl, debugWait, disposeMesh, onProgress, saveCurrTime, startFileDownload, withProgress, withTimeElapse };

0 comments on commit f5c9317

Please sign in to comment.