This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

playbackState

Summary

The playback state, initialized to UNSCHEDULED_STATE, progressing through SCHEDULED_STATE, PLAYING_STATE, and FINISHED_STATE.

Property of apis/webaudio/AudioBufferSourceNodeapis/webaudio/AudioBufferSourceNode

Syntax

Note: This property is read-only.

var result = AudioBufferSourceNode.playbackState;

Return Value

Returns an object of type unsigned shortunsigned short

Returns one of the following constant values: UNSCHEDULED_STATE (0), SCHEDULED_STATE (1), PLAYING_STATE (2), or FINISHED_STATE (3).

Examples

// 1. Create an AudioBufferSourceNode and load data into it
var soundSource = …

// 2. Check to see if the sound has finished playing, once per second
var timer = setInterval(function() {
  if (soundSource.playbackState == soundSource.FINISHED_STATE) {
    console.log("The sound has finished playing.");
    clearInterval(timer);
  }
}, 1000);

// 3. Play the sound
soundSource.start(…);

Related specifications

W3C Web Audio API
W3C Editor’s Draft