This is an addon for WebViewer that allows loading HTML5 videos (.mp4, ogg, webm) so that their video frames can be annotated.
See the npm package on @pdftron/webviewer-video for more information.
Methods
-
<async, static> initializeVideoViewer(instance, options, documentViewerNumber)
-
Initializes the video viewer so that webviewer can load videos.
Parameters:
Name Type Argument Default Description instanceObject The WebViewer instance optionsObject Options object. documentViewerNumbernumber 1 The document viewer number options.licensestring <optional>
'' The WebViewer Video license or file url. options.showFramesboolean <optional>
true Shows or hides video timeline reel. options.showTooltipPreviewboolean <optional>
true Shows or hides tooltip preview. options.renderControlsboolean <optional>
true Shows or hides the video controls. options.AudioComponentReact.Component <optional>
null The Webviewer-Audio component options.cacheAudioWaveformboolean <optional>
true Caches audio waveform on initial load options.defaultLoadAudioboolean <optional>
true Loads audio on initial load options.showFullscreenButtonboolean <optional>
true Shows or hides the fullscreen button on the video options.showSubtitlesButtonboolean <optional>
true Shows or hides the subtitles button on the video controls options.showAspectRatioGuideButtonboolean <optional>
true Shows or hides the aspect ratio guide button on the video controls options.showPlaybackSpeedButtonboolean <optional>
true Shows or hides the playback speed button on the video controls options.showAnnotationPreviewboolean <optional>
true Created annotations will have a preview in the notes panel. Turned on by default for Chromium browsers. Off for other browsers due to preview being, often, of the incorrect frame. options.openNotesPanelOnDocumentLoadedboolean <optional>
true Notes panel will be open on document loaded options.showMobileStylingboolean <optional>
false Shows or hides mobile styling options.libPathObject <optional>
The path to the video lib files. Only ffprobe files for now. options.enableRedactionObject <optional>
Enables Redaction tools. Requires a server component to run ffmpeg commands. See: https://www.pdftron.com/documentation/web/guides/video/server-component/ options.showFrameNumbersByDefaultboolean <optional>
false Shows frame numbering by default on the video controls Returns:
A promise that resolves to an object containing the functions needed to load videos in WebViewer.- Type
- VideoFunctions
Type Definitions
-
dangerouslySetNoteTransformFunction(noteTransformFunction)
-
Accepts a function that will be called every time a note in the left panel is rendered. This function can be used to add, edit or hide the contents of the note. Use this function instead of the webviewer one. The webviewer one will be overwritten by video. See WebViewer documentation dangerouslySetNoteTransformFunction.
Parameters:
Name Type Description noteTransformFunctionNoteTransformFunction The function that will be used to transform notes in the left panel. See NoteTransformFunction. Returns:
- Type
- void
Example
WebViewer(...) .then(function(instance) { const videoInstance = await initializeVideoViewer(instance, { license }); videoInstance.dangerouslySetNoteTransformFunction((wrapper, state, createElement) => { // Change the title of every note wrapper.querySelector('.author-and-time>span').innerHTML = 'My custom note title'; // Add a button that alerts the user when clicked const button = createElement('button'); button.onmousedown = (e) => { if(state.isSelected) { alert('Hello world!'); } else { alert('Goodbye world!'); } }; button.innerHTML = 'Alert me' wrapper.appendChild(button); // Add a button that makes the annotation blue const button = createElement('button'); button.onmousedown = (e) => { state.annotation.StrokeColor = new instance.Annotations.Color(0, 0, 255); instance.UI.annotManager.redrawAnnotation(state.annotation) }; button.innerHTML = 'Make me blue' wrapper.appendChild(button); }); }); -
getVideo()
-
Returns the instance of Video associated with the document. This needs to be called after the 'videoElementLoaded' event. See event:videoElementLoaded
Returns:
The instance of Video associated with the document.- Type
- object
-
loadVideo(url, options)
-
Loads a video for the WebViewer instance passed into initializeVideoViewer.
Parameters:
Name Type Description urlstring | Blob | File The video url or video file or video blob optionsObject Optional options object Properties
Name Type Argument Default Description fileNamestring <optional>
Name of the file. URLs without an extension need this property set headersObject <optional>
Custom headers to attach when making http requests to provided URL withCredentialsObject <optional>
false CORS requests for this element will have the credentials flag set to 'include' generatedPeaksArray <optional>
null An array of pre-generated peaks for corresponding video file useShakaPlayerboolean <optional>
true Runs shaka player integration instead of HTML video fpsnumber <optional>
null Sets the frames per second of the video. Usually retrieved automatically, but this option may be used incase that fails. Returns:
- Type
- void
Examples
WebViewer(...) .then(function(instance) { const license = '---- Insert commercial license key here after purchase ----'; const { loadVideo, } = await initializeVideoViewer(instance, { license }); loadVideo('https://www.mydomain.com/my_video_url'); });WebViewer(...) .then(function(instance) { const license = '---- Insert commercial license key here after purchase ----'; const { loadVideo, } = await initializeVideoViewer(instance, { license }); loadVideo('https://www.mydomain.com/my_video_url', { headers: { 'Authorization': 'Basic YWxhZGRpbjpvcGVuc2VzYW1l' }, }); }); -
renderControlsToDOM(customContainer)
-
Mounts the react component for the video controls into the passed in container. Useful when renderControls is set to false and you want to render them somewhere else.
Parameters:
Name Type Description customContainerObject A container element, e.g. a div. Returns:
- Type
- void
Example
WebViewer(...) .then(function(instance) { const license = '---- Insert commercial license key here after purchase ----'; const { loadVideo renderControlsToDOM, } = await initializeVideoViewer( instance, { license, renderControls: false, }, ); ... instance.docViewer.addEventListener'documentLoaded', (e) => { const customContainer = instance.iframeWindow.document.querySelector('.custom-container'); renderControlsToDOM(customContainer); }); }); -
VideoFunctions
-
Type:
- Object
Properties:
Name Type Description getVideogetVideo Returns the instance of Video associated with the document. loadVideoloadVideo Loads a video for the WebViewer instance passed into initializeVideoViewer. renderControlsToDOMrenderControlsToDOM Mounts the react component for the video controls into the passed in container. Useful when renderControls is set to false and you want to render the controls somewhere else. dangerouslySetNoteTransformFunctiondangerouslySetNoteTransformFunction Accepts a function that will be called every time a note in the left panel is rendered. This function can be used to add, edit or hide the contents of the note. Use this function instead of the webviewer one. The webviewer one will be overwritten by video. See WebViewer documentation dangerouslySetNoteTransformFunction. UIUI The UI namespace of WebViewer Video, used to update UI elements of WebViewer Video.
Events
-
videoElementLoaded
-
Event emitted when video element gets initialized
Example
WebViewer(...) .then(function(instance) { const { docViewer } = instance; docViewer.addEventListener('videoElementLoaded', listener); }); -
videoPause
-
Event emitted when video gets paused
Example
WebViewer(...) .then(function(instance) { const { docViewer } = instance; docViewer.addEventListener('videoPause', listener); }); -
videoPlay
-
Event emitted when video begins playing
Example
WebViewer(...) .then(function(instance) { const { docViewer } = instance; docViewer.addEventListener('videoPlay', listener); });