Markers
If you do decide to add markers yourself, rather than rely on automatic detection, we recommend you set the markers to a randomly generated UUID. The UUID must be stable, that is to say, it must not change between page refreshes. If you are using the client-side integration, the markers will be automatically retrieved from your page when content is processed. If you are sending HTML to the BeyondWords API, the markers will be automatically extracted from the HTML when content is processed. If you are sending plaintext to the BeyondWords API, you will need to set the marker attribute on each segment alongside the text. Alternatively, if a segment marker is not provided, BeyondWords will generate one for you. You can retrieve these from the/content endpoint and add them to the HTML of your article.
It is recommended to generate UUIDs as markers to avoid duplicates, in case there are multiple players on the same page.
How it works
Once the player script has loaded, it will add global listeners to your page to detect clicks and mousemove events. If the player detects that you are hovering or have clicked on an element, it will try to match that element against the segments using markers (see above), xpath or an MD5 fingerprint of the text content. If a match is found, the player emitsHoveredSegmentUpdated and PressedSegment events.
Additionally, when the currentTime of the media updates (i.e. by playing it), the player emits a CurrentSegmentUpdated event.
These events are then used to highlight segments on the page and to control playback, e.g. by setting its currentTime to the startTime of the segment that the user clicked on. The currentSegment and hoveredSegment props of the player are set.
To highlight segments, the player adds a <mark> element inside the segment on the page with some custom styles. All children of the segment are moved inside of the mark. The mark is removed again after highlighting has ended.
To avoid interfering with your page, highlighting and clicking on segments does not trigger if you are hovering over a link or other element with a ‘click’ or ‘mousedown’ handler. However, this does not apply to event listeners (see below).
Event listeners
Unfortunately, the player cannot detect event listeners that have been registered on elements within the segment. For example, this button does not have an ‘onclick’ property and therefore playback will be affected when it is clicked.event.preventDefault() at the top of the event listener:
Player settings
Playback from Segments supports various Player Settings:- highlightColor can be used to set a different highlight color for segments on the page
- highlightSections can be used to control which segments highlighting applies to (if any)
- clickableSections can be used to control which segments can be clicked on (if any)
- segmentWidgetSections can be used to control which segments the widget appears next to (if any)
- segmentWidgetPosition can be used to control which side the widget appears next to the segment
- currentSegment can be used to get the current segment (this is a read-only property)
- hoveredSegment can be used to get the hovered segment (this is a read-only property)