How to use the platform/platform.performance.now function in platform

To help you get started, we’ve selected a few platform examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github petkaantonov / HTML-Music-Player / src / audio / frontend / AudioManager.js View on Github external
_checkAudioContextStaleness() {
        if (this._audioContext.state === `running`) {
            if (this._suspensionTimerStartedTime !== -1 &&
                performance.now() - this._suspensionTimerStartedTime > this._suspensionTimeoutMs) {
                this._suspensionTimerStartedTime = -1;
                this._resetAudioContext();
            }
            return;
        }

        // Reset AudioContext as it's probably ruined despite of suspension efforts.
        if (!this._currentStateModificationAction) {
            this._resetAudioContext();
        } else if (this._currentStateModificationAction.type === `suspend`) {
            this._currentStateModificationAction = null;
            this._resetAudioContext();
        }
    }
github petkaantonov / HTML-Music-Player / src / player / PlayerController.js View on Github external
_playbackProgressed(currentTime, totalTime) {
        if (!this._tickCounter.hasTriggered() &&
            this._loadedTrack && currentTime >= 5 && totalTime >= 10) {
            if (this._tickCounter.tick()) {
                this._loadedTrack.triggerPlaythrough();
            }
        }

        const now = performance.now();
        if (now - this._progressLastPersisted > 500 &&
            this._lastPersistedProgressValue !== this._getUnroundedProgress()) {
            this._progressLastPersisted = now;
            this._lastPersistedProgressValue = this._getUnroundedProgress();
            this._persistProgress();
        }

        this.emit(PROGRESS_EVENT, currentTime, totalTime);
    }
github petkaantonov / HTML-Music-Player / src / audio / AudioPlayerAudioBufferImpl.js View on Github external
if (sourceDescriptor.isLastForTrack &&
            sourceDescriptor.endTime < this._duration - this._player.getBufferDuration()) {
            this._duration = sourceDescriptor.endTime;
            this._emitTimeUpdate(this._currentTime, this._duration);
            this.emit(`durationChange`, this._duration);
        }

        if (this._baseGain === 1 && !isNaN(descriptor.loudness)) {
            this._baseGain = decibelToGain(descriptor.loudness);
            if (!currentSourcesShouldBeStopped && !this._sourceStopped) {
                this._rescheduleLoudness();
            }
        }

        const now = performance.now();
        if (currentSourcesShouldBeStopped) {
            scheduledStartTime = Math.max(scheduledStartTime, this.getCurrentTimeScheduledAhead());
            if (!this._sourceStopped) {
                this._stopSources(scheduledStartTime, true);
            }

            this._playedBufferQueue.push(...this._bufferQueue);
            this._bufferQueue.length = 0;
            this._bufferQueue.push(sourceDescriptor);

            if (this._sourceStopped) {
                this._startSources(scheduledStartTime);
            } else {
                this._startSource(sourceDescriptor, scheduledStartTime);
            }
        } else if (this._sourceStopped) {
github petkaantonov / HTML-Music-Player / src / visualization / VisualizerCanvas.js View on Github external
enabledMediaMatchChanged() {
        this.binSizeMediaMatchChanged();
        if (this.source && this.source.isReady()) {
            this.drawIdleBins(performance.now());
        }
    }
github petkaantonov / HTML-Music-Player / src / audio / frontend / AudioPlayer.js View on Github external
playbackStopped() {
        this._clearSuspensionTimer();
        this._playbackStoppedTime = performance.now();
        this._suspensionTimeoutId = this.page.setTimeout(this._suspend, this._suspensionTimeoutMs);
    }
github petkaantonov / HTML-Music-Player / src / visualization / AudioVisualizer.js View on Github external
const {actualFps} = this;
            const offsetSeconds = (actualFps > 0 ? (1000 / actualFps / 1000) : 1000 / this.targetFps) -
                                    this._getAudioLatency();

            const frameDescriptor = this.audioManager.getSamplesScheduledAtOffsetRelativeToNow(this._channelData, offsetSeconds);

            if (!frameDescriptor.channelDataFilled) {
                return;
            }

            const binCount = this.binCount();
            if (!this._bins || this._bins.length !== binCount) {
                this._bins = new Float64Array(binCount);
            }

            const now = performance.now();
            this._awaitingBins = true;
            await this._getBins(frameDescriptor);
            const fps = 1000 / (performance.now() - now);
            this._workerFps = (this._workerFps * (1 - ALPHA)) + fps * ALPHA;
        }
    }
github petkaantonov / HTML-Music-Player / src / audio / frontend / AudioManager.js View on Github external
_startSuspensionTimer() {
        this._clearSuspensionTimer();
        this._suspensionTimerStartedTime = performance.now();
        this._suspensionTimeoutId = this.page.setTimeout(this._suspend, this._suspensionTimeoutMs);
    }
github petkaantonov / HTML-Music-Player / src / ui / Snackbar.js View on Github external
_timeoutChecker() {
        this._checkerTimerId = -1;
        if (this._exiting) return;
        const {visibilityTime} = this;
        const shownTime = this._startedShowing === -1 ? 0 : performance.now() - this._startedShowing;

        if (!this._snackbar.globalEvents.isWindowBackgrounded() && !this._isHovering) {
            if (shownTime > visibilityTime) {
                this.outcome = TIMED_OUT;
                this._hide();
            } else {
                this._checkerTimerId = this.page().setTimeout(this._timeoutChecker, Math.max(0, visibilityTime - shownTime));
            }
        }
    }