Firefox Tomorrow

web api instance method

AudioPlaybackStats: toJSON() method

View on MDN ↗

Limited availability

The toJSON() method of the AudioPlaybackStats interface is a serializer; it returns a JSON representation of the AudioPlaybackStats object.

Syntax

toJSON()

Parameters

None.

Return value

A JSON object that is the serialization of the AudioPlaybackStats object.

Examples

Using the toJSON method

In this example, calling stats.toJSON() returns a JSON representation of the AudioPlaybackStats object.

const audioCtx = new AudioContext();
const stats = audioCtx.playbackStats;

// ...

// Log playbackStats JSON
console.log(stats.toJSON());

This would log a JSON object like so:

{
  "underrunDuration": 0,
  "underrunEvents": 0,
  "totalDuration": 68.252138,
  "averageLatency": 0.01863,
  "minimumLatency": 0,
  "maximumLatency": 0.018654
}

To get a JSON string, you can use JSON.stringify(stats) directly; it will call toJSON() automatically.

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also