API for getting audio playtime


Would PlayCanvas implement a new API which let us get the playtime of the audio? I like to use the code to sync my model’s motion and BGM.

I thought exposing HTML5 audiocontext currentTime might be enough. But as far as I saw the engine code, it didn’t seem that simple…


I tried to use this code hoping I can use “currentTime” value instead of the new API. I could sync the music and motion on Chrome successfully by adjusting the offset seconds between the music and motion based on currehtTime. But when I played the adjusted code on Firefox, Firefox plays the motion consistently earlier than Chrome and it seemed Firefox needs different offset value. Still investigating…

(FYI, IE11 can’t play ogg vorbis. I tried to upload m4a but PlayCanvas automatically converts it to ogg. IE11 also shows out of memory error while parsing animation JSON, 21.9MB for one model and 15.8MB for another model)

pc.script.create('audio', function (app) {
    // Creates a new Audio instance
    var Audio = function (entity) {
        this.entity = entity;

    Audio.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () {
             this.currentTime = 0;

        // Called every frame, dt is time in seconds since last update
        update: function (dt) {
            this.currentTime += dt;

    return Audio;