Skip to content
marisademeglio edited this page May 11, 2012 · 24 revisions

Playback mechanisms

HTML 5 audio

Reference: HTML5 audio element

pros:

  • buffers automatically and does a reasonable job
  • can easily set start position
  • built-in playback rate control

cons:

  • some glitching when setting currentTime (used to point the player at the start of a clip); however, this can be worked around fairly easily.
  • have to use timeout/setinterval to monitor for end of clip

If we only reset the currentTime when it is out of clipBegin/clipEnd boundaries, then glitching seems to go away.

If we encounter issues with loading files, we can create an asset manager to pre-load audio assets. In this case, it would be helpful to list all the audio assets related to SMIL when the book loads; of course, this can't be done without analyzing all the SMIL files, which could get expensive. One compromise might be to have the MO component, which deals with one file at a time, pre-load audio assets of a single file.

Web audio

Reference: web audio

pros:

  • no glitching
  • can specify clip duration up front
  • can accept audio filters, for example to scale the playback rate without affecting the pitch

cons:

  • have to use timeout/setinterval to monitor the status of an audio clip
  • have to manage buffer manually, and it can be slow to load

future pros:

  • need for timeout/setinterval monitoring will go away in the future (see this bug)

If we were to use web audio, we would have to progressively buffer windows of data (for example, 1MB at a time). Until it supports clip-done callbacks, we might not need the full power of web audio.

Synchronization issues

There is an issue that if the tab moves to the background, audio playback is affected because the interval is checked only once every second (read more). There are some methods to work around this.

Check currentTime vs incoming clip boundaries

If the currentTime is within the clip boundaries, and the clips are the same, then don't reset currentTime, just keep playing.

The worst that can happen is that the file of the previous clip keeps playing even when it shouldn't; i.e. the tree has non-contiguous clips. This would happen for max one second when the tab is out of focus, and would be corrected as the next clip is loaded.

Integrity check

This type of check involves back-calculating the current SMIL node based on audio player position. It could potentially be an expensive search operation, so its use should be minimized; for example, it could be used only when the tab comes back into focus. The trouble with this method is that it could bypass non-contiguous clips inserted in the middle of the tree. It would have to be used in conjunction with something similar to the method above, without overriding it.

Decisions

HTML5 audio with a currentTime check.