Options
All
  • Public
  • Public/Protected
  • All
Menu

Used for playing synchronized media such as EPUB Media Overlays or TTS (Text-To-Speech).

The SyncMediaPlayer coordinates the playback of a SyncMediaTimeline and exposes methods for controlling playback, such as play/pause/skip.

Create a new player by calling ReadingSystemEngine.createSyncMediaPlayer(syncMediaTimeline). SyncMediaTimeline can be created from ReaderPublication instances. For example: EpubReaderPublication.createMediaOverlaySyncMediaTimeline() or EpubReaderPublication.createTtsSyncMediaTimeline().

The SyncMediaTimeline can consist of various media formats such as audio, video, TTS, content highlighting instructions. Several media objects can be played parallel. The actual playback of each type of media is handled by SyncMediaObjectRenderers. All this is handled by the SyncMediaPlayer.

By default, SyncMediaPlayer will create default SyncMediaObjectRenderer using SyncMediaTimeline.createDefaultMediaObjectRenderers(). You can override this behaviour by setting the SyncMediaPLayerInitOption addDefaultMediaObjectRenderers to false, and then manually call addMediaObjectRenderer() for each media type you wish to support.

A SyncMediaPlayer is able to synchronize playback position with publication content visible in the ReaderView. This can be used to enable features such as test highlighting, automatic page turn, etc. To enable this feature, call readerView.setSyncMediaPlayer().

Hierarchy

Index

Methods

addEngineEventListener

addMediaObjectRenderer

  • Adds a SyncMediaObjectRenderer to this player, possibly replacing an existing media object renderer if they handle the same SyncMediaObjectRefType.

    throws

    an error if the renderer is not compatible with the timeline.

    Parameters

    Returns void

attemptReaderViewSynchronization

  • Attempts to synchronize the player with the ReaderView using the given method.

    If managed synchronization is enabled, this method is called automatically by the reading system. See SyncMediaPlayer.setManagedReaderViewSynchronization() for more details.

    If the SyncMediaPlayer is not attached to a ReaderView, this method does nothing.

    Parameters

    • method: SyncMediaReaderViewSynchronizationMethod

      the method that will be used to attempt synchronization.

    • Optional timelinePosition: ISyncMediaTimelinePosition

      If set, it will be used instead of resolving a new SyncMediaTimelinePosition from the ReaderView's readingPosition. (Only relevant if method is SEEK_SYNC_MEDIA)

    • Optional contentLocation: IContentLocation

      If set, it will be used instead of resolving a new ContentLocation from the current timelinePosition. (Only relevant if method is NAVIGATE_VIEW_GOTO)

    Returns void

getApproximateElapsedTimeMs

  • getApproximateElapsedTimeMs(): number
  • Gets the approximate elapsed time from timeline start to current position in milliseconds.

    Returns number

getApproximateElapsedTimeMsForTimelinePosition

  • Get the approximate elapsed time from timeline start in milliseconds to the specified timeline position.

    deprecated

    Use ISyncMediaTimeline.getApproximateOffsetMs() instead.

    Parameters

    Returns number

getEngineEventListeners

getMediaObjectRenderers

getName

  • getName(): string
  • Get the name of this SyncMediaPlayer.

    Returns string

getPlaybackRange

  • Returns the current active playback range, previously set with setPlaybackRange(). Returns null if there is no active playback range.

    Returns ISyncMediaPlaybackRange

getPlaybackRate

  • getPlaybackRate(): number
  • Get the current playback rate, where 1.0 means normal speed. For example: 0.5 is half speed, and 2.0 is double speed.

    Returns number

getReaderView

  • Get the ReaderView instance that this player is currently attached to.

    Returns IReaderView

getReaderViewSynchronizationWaitBehavior

getReadingSystemEngine

getSkippabilityOptions

getTimeline

getTimelinePosition

getVolume

  • getVolume(): number
  • Get the current volume as a value between 0.0 and 1.0

    Returns number

isAtEnd

  • isAtEnd(): boolean
  • If the player has reached the end of the timeline. Calling play() has no effect when this method returns true.

    Returns boolean

isAtStart

  • isAtStart(): boolean
  • If the player is currently at the start of the timeline.

    Returns boolean

isDestroyed

  • isDestroyed(): boolean
  • Checks if this instance has been destroyed.

    Returns boolean

isMuted

  • isMuted(): boolean
  • If audio is muted.

    Returns boolean

isPaused

  • isPaused(): boolean
  • If the player is currently paused.

    Even if this method returns false, the player might still be waiting for media to load or for ReaderView synchronization. Also see isWaitingForMediaObjectRenderers() and isWaitingForReaderViewSynchronization().

    Returns boolean

isPlaying

  • isPlaying(): boolean
  • If the player is currently playing media. This is a shorthand for: !isPaused() && isReady()

    Returns boolean

isReady

  • isReady(): boolean
  • True if the media player is ready to play. False if either isWaitingForReaderViewSynchronization() or isWaitingForMediaObjectRenderers() returns true.

    Clients can still call play() to make the media player resume playback when it has reached ready state.

    Returns boolean

isSeeking

  • isSeeking(): boolean
  • Returns true if the player is currently seeking to a new timeline position.

    Returns boolean

isWaitingForMediaObjectRenderers

  • isWaitingForMediaObjectRenderers(): boolean
  • Returns true if the player is waiting for SyncMediaObjectRenderers to load data.

    Returns boolean

isWaitingForReaderViewSynchronization

  • isWaitingForReaderViewSynchronization(): boolean
  • Returns true if the player is waiting to become synchronized with the ReaderView.

    Returns boolean

pause

  • pause(): void
  • Pause playback.

    Returns void

play

  • play(): void
  • Attempts to resume playback from the current timeline position as soon as the player is ready. The player will pause if it fails to resume playback.

    Returns void

removeEngineEventListener

removeMediaObjectRenderer

  • Removes the specified SyncMediaObjectRenderer from this player.

    Parameters

    Returns boolean

    true if the renderer was found and removed, false otherwise.

removePlaybackRange

  • removePlaybackRange(): void
  • If the SyncMediaPlayer has an active playback range, it will be removed, and the engine event syncMediaRangePlaybackRemoved will be emitted by the reading system. The event object's reason property will be set to SyncMediaRangePlaybackRemoveReason.APP_GENERATED.

    This method has no effect if the SyncMediaPlayer don't have an active playback range.

    Returns void

seekToApproximateTimeMs

  • seekToApproximateTimeMs(timeMs: number): boolean
  • Seek to the approximate time from timeline start in milliseconds.

    Parameters

    • timeMs: number

    Returns boolean

    true if the player started seeking, false if it was not possible to do so.

seekToNextSegment

  • seekToNextSegment(snapToVisiblePagesBoundary?: boolean): boolean
  • Seeks to the next segment in the timeline, if such segment exists.

    Parameters

    • Optional snapToVisiblePagesBoundary: boolean

      If set to true while seeking from a segment that spans across the end of the currently visible pages and the next page(s), the media player will seek inside that segment to match the start position of the content on the next page. Calling seekToNextSegment again will then seek to the beginning of the next segment. If set to false, the media player will seek to the beginning of the next segment.

    Returns boolean

    true if the player started seeking to the new segment, false if it was not possible to do so.

seekToPreviousSegment

  • seekToPreviousSegment(snapToVisiblePagesBoundary?: boolean): boolean
  • Seeks to the previous segment in the timeline, if such segment exists.

    Parameters

    • Optional snapToVisiblePagesBoundary: boolean

      If set to true while seeking to a segment that spans across the beginning of the currently visible pages and the previous page(s), the media player will seek inside that segment to match the starting position of the currently visible content. Calling seekToPreviousSegment again will then seek to the beginning of the segment. If set to false, the media player will seek to the beginning of the previous segment.

    Returns boolean

    true if the player started seeking to the new segment, false if it was not possible to do so.

seekToTimelinePosition

setManagedReaderViewSynchronizationOptions

setMuted

  • setMuted(muted: boolean): void
  • Set if audio should be muted.

    Parameters

    • muted: boolean

    Returns void

setPlaybackRange

  • Sets a new active playback range on this SyncMediaPlayer, and by default, immediately seeks to range.start.

    When the SyncMediaPlayer reaches range.end during playback, it will automatically pause and the engine event syncMediaRangeEndReached will be emitted by the reading system. By default, the playback range is removed when the SyncMediaPlayer reaches range.end, but you can change this behaviour by setting removeRangeOnEndReached to false in the options object.

    Playback range removal

    An active playback range can be removed by calling removedPlaybackRange().

    The playback range may also be removed due to seeking, either by calling any of the seek methods in ISyncMediaPlayer, or due to a synchronization operation with an attached ReaderView. You can control how seeking affects the active playback range by setting a seekBehavior in the options object.

    When a playback range is removed, the engine event syncMediaRangePlaybackRemoved is emitted by the reading system. The property ISyncMediaRangeEngineEvent.reason contains details to why the playback range was removed.

    throws

    EngineError if: - the passed timeline positions are from another SyncMediaTimeline. - the end position is before start position. - the SyncMediaPlayer has been destroyed.

    Parameters

    Returns ISyncMediaPlaybackRange

    The resulting playback range.

setPlaybackRate

  • setPlaybackRate(playbackRate: number): void
  • Sets the playback rate of the media player as a value between 0.25 and 5.0.

    A value of 1.0 means "normal speed". Values less than 1.0 make the media to play slower than normal. Values greater than 1.0 make it play faster.

    Parameters

    • playbackRate: number

      The new playback rate. The value will be clamped between 0.25 and 5.0.

    Returns void

setReaderViewSynchronizationWaitBehavior

  • Sets the synchronization wait behavior for the SyncMediaPlayer when it is attached to a ReaderView. The default value is WAIT_OUTSIDE_ADJACENT. See SyncMediaPlayerViewSynchronizationBehavior for a description on how each mode works.

    Parameters

    Returns void

setSkippabilityOptions

setVolume

  • setVolume(volume: number): void
  • Sets the volume for the media player as a value between 0.0 and 1.0.

    Parameters

    • volume: number

      The new volume. The value will be clamped between 0.0 and 1.0.

    Returns void

Generated using TypeDoc