Access currentTime of sound (character has both animation and sound slots)

So, if I understand correctly from your code, you are trying to get per frame the time remaining for the sound playing to finish?

I think you just need to grab a reference to the sound instance playing, not to the sound slot:

var TestSoundCurTime = pc.createScript('testSoundCurTime');

// initialize code called once per entity
TestSoundCurTime.prototype.initialize = function() {
    this.soundTogetCurrTime = this.entity.sound.slot("test"); 
    console.log("stgs: "+this.soundTogetCurrTime.name);
    
    this.soundInstance = this.playSound();
};

// update code called every frame
TestSoundCurTime.prototype.update = function(dt) {
    
    console.log("getCurTim - duration: ", this.soundInstance.currentTime - this.soundTogetCurrTime.duration);
};

TestSoundCurTime.prototype.playSound = function(){
    return this.entity.sound.play("test");   
};
1 Like