I want to pause a sound in a sound slot and resume playback from where it was paused. I think this is suppose to be the normal behavior. But instead of resuming the audio track from where it was paused, it start from the beginning. I did a small and clean public project if someone wants to take a look at my current code:
https://playcanvas.com/project/521663/overview/pauseresume-audio-test
I’m probably doing something wrong.
Here’s the code:
var PauseResumeAudioTest = pc.createScript('pauseResumeAudioTest');
PauseResumeAudioTest.attributes.add('audioTrack', {
type: 'entity',
});
// initialize code called once per entity
PauseResumeAudioTest.prototype.initialize = function() {
};
// update code called every frame
PauseResumeAudioTest.prototype.update = function(dt) {
if (this.app.keyboard.isPressed(pc.KEY_P)) {
if(this.audioTrack && this.audioTrack.sound.slot("Slot 1").isPaused === true){
this.audioTrack.sound.slot("Slot 1").resume();
}
} else {
if(this.audioTrack && this.audioTrack.sound.slot("Slot 1").isPaused === false){
this.audioTrack.sound.slot("Slot 1").pause();
}
}
};