Add functionality to upload captions from local filesystem #1464
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added functionality to upload captions.
Here's a demo
Link to related issue (if applicable)
Summary of proposed changes
The default config's
captionsproperty has been changed as follows:captions: { active: false, language: 'auto', // Listen to new tracks added after Plyr is initialized. // This is needed for streaming captions, but may result in unselectable options update: false, + // Allow uploading captions from local filesystem. + // Once a file is selected, + // This either requires update to be true or the developer needs to call + upload: { + enabled: false, + // The formats that are valid + formats: ['vtt'], + // Set to true if you're allowing formats other than vtt where the input needs to be processed. + // This is useful in cases where the developer allows selecting of + // formats such as srt, ssa, etc, which need to be converted into vtt + // before plyr can add it as a track element. + callback: false, + // The event that plyr will trigger when the user has selected a file and callback is true. + // If null, then plyr will treat the file as a VTT file and directly add it + onInput: 'trackinput', + // The event that plyr will listen for when callback is true. + // If null, then plyr will treat the file as a VTT file and directly add it. + onProcessed: 'inserttrack', + }, }If
captions.upload.enabledis set to true, then:A hidden
<input type="file">object is created and listeners are set up for this. When the 'Upload Captions' option is clicked, a click is simulated on this<input type="file">element which allows the user to upload a file.The default configuration only allows uploading VTT files and has no callbacks for the developers to make any changes. However, by setting
captions.upload.callback = true, the developer can listen for the event specified undercaptions.upload.onInputto know when the user has selected a file and perform operations on the file's text. These operations may involve converting from various formats into the WebVTT format. Once all operations are completed, the developer is expected to trigger the event specified undercaptions.upload.onProcessedto tell Plyr to add the processed text as aTextTrack.Checklist
developas the base branch/distchanges) from the PR