- Highlight paragraphs: Highlight the paragraph currently being read aloud, helping users follow along with the audio
- Highlight words: Highlight individual words as they are spoken, creating an immersion reading experience
- Playback from paragraphs: Allow users to click or tap a paragraph to begin playback from that point
JavaScript
If you’re using the JavaScript player and segment detection isn’t working properly, you can add markers to elements on your page to improve detection accuracy:Markers
If you add markers manually, we recommend using randomly generated UUIDs. Markers must be stable and should not change between page refreshes.- If you’re using the client-side integration, markers will be automatically retrieved from your page when content is processed
- If you’re sending HTML to the BeyondWords API, markers will be automatically extracted from the HTML when content is processed
- If you’re sending plaintext to the BeyondWords API, you will need to set the marker attribute on each segment alongside the text
?segments=full) and add them to the HTML of your article.
We recommend generating 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 adds global listeners to your page to detect click and mousemove events. When a user hovers over or clicks on an element, the player attempts to match that element against 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 (e.g., during playback), the player emits a CurrentSegmentUpdated event.
These events are used to highlight segments on the page and control playback—for example, by setting currentTime to the startTime of the segment the user clicked on. The currentSegment and hoveredSegment properties of the player are also updated accordingly.
To highlight segments, the player wraps the segment content in a <mark> element with custom styles. The mark is removed once highlighting ends.
To avoid interfering with your page, highlighting and click handling are disabled when hovering over a link or an element with a click or mousedown handler. Note that this does not apply to event listeners (see below).
Event listeners
The player cannot detect event listeners registered on elements within a segment. For example, the button below does not have anonclick property, so playback will be affected when it is clicked:
event.preventDefault() at the top of the event listener:
Configuration
Playback from paragraphs can be configured using the following player properties:| Property | Description |
|---|---|
highlightColor | Set a custom highlight color for segments |
highlightSections | Control which segments highlighting applies to |
clickableSections | Control which segments can be clicked on |
segmentWidgetSections | Control which segments the widget appears next to |
segmentWidgetPosition | Control which side the widget appears next to the segment |
currentSegment | Get the current segment (read-only) |
hoveredSegment | Get the hovered segment (read-only) |
Mobile SDKs
The mobile SDK implementations are based on the JavaScript version above. Unlike the JavaScript player, the mobile SDKs cannot automatically identify segments—you will need to manually link each text segment to its BeyondWords marker.- Android
- iOS
You can find a full example of playback from paragraphs integration in the Android GitHub repository:
Highlighting the current segment
Listen for theCurrentSegmentUpdated event, then find the corresponding UI element and apply your desired styling:Handling segment clicks
Set aView.OnClickListener and call setCurrentSegment with the corresponding marker: