This is an addon for WebViewer that allows loading media files (.mp3, .mp4, .ogg, .webm, etc.) so that the audio track can be annotated.
See the npm package on @pdftron/webviewer-audio for more information.
Methods
-
<async, static> initializeAudioViewer(instance, options)
-
Initializes the audio viewer so that WebViewer can load media files.
Parameters:
Name Type Description instance
Object The WebViewer instance options
Object Options object. Properties
Name Type Argument Default Description license
string <optional>
'' The WebViewer Audio license. Returns:
A promise that resolves to an object containing the functions needed to load videos in WebViewer.- Type
- AudioFunctions
Example
WebViewer(...) .then(function(instance) { const license = '---- Insert commercial license key here after purchase ----'; const { loadAudio, getFileURL, } = await initializeAudioViewer( instance, { license, }, ); loadAudio('https://www.mydomain.com/my_audio_url'); instance.docViewer.on('documentLoaded', () => { // Download the file const anchor = document.createElement('a'); anchor.href = getFileURL(); anchor.target = "_blank"; anchor.download = myAudioFile.mp3; // Auto click on a element, trigger the file download anchor.click(); }); });
Type Definitions
-
AudioFunctions
-
Type:
- Object
Properties:
Name Type Description loadAudio
function Loads an audio file for the WebViewer instance passed into initializeAudioViewer. First param is the audio/video url. getFileURL
function Can only be used in licensed mode. In the demo mode it will only return `null`. Returns the file URL loaded through `loadAudio` until redactions are made. After redactions are made the URL will be a Data URL for the modified file. redactAudio
function Redacts ranges of time in the audio. It takes one param, an array of objects with the shape: { start: startTime , end: endTime }. `start` and `end` time are both expected to be in seconds. Returns a promise that resolves when the operation is complete. Only one of these operations may be run at the same time. You must wait for the previous operation to finish before beginning another. Example
WebViewer(...) .then(function(instance) { const license = '---- Insert commercial license key here after purchase ----'; const { loadAudio, getFileURL, redactAudio, } = await initializeAudioViewer( instance, { license, }, ); loadAudio('https://www.mydomain.com/my_audio_url'); instance.docViewer.on('documentLoaded', async () => { // Download the file const anchor = document.createElement('a'); anchor.href = getFileURL(); anchor.target = "_blank"; anchor.download = myAudioFile.mp3; // Auto click on a element, trigger the file download anchor.click(); // Redact the audio track 0.5 - 2.0 seconds and 2.5 - 4.0 seconds. await redactAudio([ { start: 0.5, end: 2.0 }, { start: 2.5, end: 4.0 } ]); }); });