Implements range looping for an {IMediaHandler}, including fading.

Remarks

Implements optional audio fading at the loop boundaries, with the help of an {IAudioFader}.

Devdoc

This IMediaHandler based approach (with observing of the current time on the wrapped media element) is used to emulate the buffer looping for the enclosed media element. Replayer does intentionally not use buffered audio sources, to be able to play online media without CORS headers. See https://www.w3.org/TR/webaudio/#looping-AudioBufferSourceNode for information about looping.

Implements

Constructors

Properties

_isPaused: boolean = true

Whether media playback is paused

_loopEnd: null | number = null

The loop end

_loopMode: LoopMode = LoopMode.Recurring

The loop mode (recurring by default)

_loopStart: null | number = null

The loop start

The media handler to act upon

isLoopEndHandling: boolean = false

Whether the loop end is currently handeled (by possibly fading and then by seeking back to the start).

Remarks

This is (an internal) flag to prevent re-triggering of fade-outs and seeks when loop end handling is already in progress

loopSeekingDurationToCompensate: number = 0.01

A measured duration for the seek operation when executing a loop in [seconds]. This is used to compensate the seek target with, to have the loop start accounted for this duration

Remarks

This value is measured at each executed loop. The initially set value is a reasonable default.

nonReschedulingMargin: number = 0.3

The range for which a too short loop timer is not rescheduled.

Remarks

Experience has shown, that small rescheduling near the end of the actual loop end worsen the loop timing. These are prevented within this margin.

schedulingHandle: null | Timeout = null

A handle to the scheduler for lopp handling

trackDurationSafetyMarginSeconds: number = 0.1

A safety margin for detecting the end of a track during playback while looping

Remarks

This value was empirically determined. It's dependent of CPU power and timing accurracy

useFadingOnLoopBoundaries: boolean = false

Whether to use fading on loop boundaries

Remarks

Off by default to provide continuous playback when looping back to the start.

Accessors

  • get loopEnd(): null | number
  • Gets the end time of the loop range.

    Returns null | number

  • get loopStart(): null | number
  • Gets the start time of the loop range.

    Returns null | number

Methods

  • Executes a due loop for the given timings

    Parameters

    • start: number

      The start of the loop in [seconds]

    • end: number

      The end of the loop in [seconds]

    • loopMode: LoopMode

      how to handle the possible loop

    Returns void

    Remarks

    Determines whether a loop is deemed required due to the timings and returns a boolean accordingly

  • Gets the time remaining until of the end of the loop range, with a safety margin applied for loop detection at the track end

    Parameters

    • currentTime: number
    • loopEnd: number

    Returns number

  • Determines whether the looping range is well defined (boundaries are properly set)

    Returns boolean

  • Schedules the next loop handling, with it's checking for due loops.

    Returns void

    Remarks

    To minimize resource usage, this should be called only when necessary. This includes seek and play operations.

  • Updates the measured loop seeking duration using the given measured start and end times (in [milliseconds]) of the loop seeking operation

    Parameters

    • tStart: number
    • tFinish: number

    Returns void

    Remarks

    Applies some simple averaging