• rtoy@chromium.org's avatar
    Implement suspend/resume for AudioContext · a6646b64
    rtoy@chromium.org authored
    WebAudio is adding a suspend()/resume() API:
    
    https://github.com/WebAudio/web-audio-api/issues/361
    https://github.com/WebAudio/web-audio-api/issues/317
    
    In more detail, here is the proposed additions to the spec:
    
    New attribute "state" with values:
    paused
      Currently paused (time is not proceeding, audio hardware may be powered down/released).
    running
      Audio is being processed.
    released
      AudioContext has been released, and can no longer be used to process audio. All system resources should be released.
    
    void suspend()
    Suspends the progression of time in the audio context, allows any current buffer contents to be played to the destination and then allows the system to power down and/or release audio hardware. If the context has been released, an InvalidStateError MUST be thrown. This is generally useful when the application knows it will not need the AudioContext for some time, and wishes to let the audio hardware power down.
    
    While the system is suspend, MediaStreams will have their output ignored; that is, data will be lost by the real time nature of media streams. HTMLMediaElements will similarly have their output ignored until the system is resumed. Audio Workers and ScriptProcessorNodes will simply not fire their onaudioprocess events while suspended, but will resume when resumed. For the purpose of AnalyserNode window functions, the data is considered as a continuous stream - i.e. the resume()/suspend() does not cause silence to appear in the AnalyserNode's stream of data.
    
    Promise resume()
    Resumes the progression of time in the audio context, which may involve re-priming the frame buffer contents. The promise resolves when the system has re-acquired (if necessary) access to audio hardware and has begun streaming to the destination, or immediately (with no other effect) if the context is already running. The promise is rejected if the context has been released.
    
    BUG=420106
    
    Review URL: https://codereview.chromium.org/625363004
    
    git-svn-id: svn://svn.chromium.org/blink/trunk@183916 bbb929c8-8fbe-4397-9dbb-9b2b20218538
    a6646b64
audiocontext-suspend-resume.html 2.99 KB