-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mediaPlayer.addTextTrack()
#3573
Open
malthejorgensen
wants to merge
9
commits into
Dash-Industry-Forum:development
Choose a base branch
from
eduflow:api-add-remote-text-track
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
03317ed
Add `MediaPlayer.addTextTrack`-method
malthejorgensen b1672ba
Don't override current captions -- add a new track
malthejorgensen 400c5a8
addTextTrack: Add `mediaInfo`-argument
malthejorgensen b32c526
Add TextTracks.getNumberOfTextTracks()
malthejorgensen 599d31a
Remove unused comments
malthejorgensen e369a9b
CaptionsLoader: Remove unused `baseUri`
malthejorgensen e65cc56
external-caption-vtt sample: Use relative URL
malthejorgensen 97006db
CaptionsLoader.js: Remove unused comment
malthejorgensen 39773bb
External captions: Reuse `TextSourceBuffer.createTextTrackFromMediaInfo`
malthejorgensen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<title>WebVTT Dash Demo</title> | ||
<meta name="description" content="" /> | ||
<link rel="icon" type="image/x-icon" href="http://dashif.org/wp-content/uploads/2014/12/dashif.ico" /> | ||
|
||
<script src="../../dist/dash.all.debug.js"></script> | ||
<!--dash.all.min.js should be used in production over dash.all.debug.js | ||
Debug files are not compressed or obfuscated making the file size much larger compared with dash.all.min.js--> | ||
<!--<script src="../../dist/dash.all.min.js"></script>--> | ||
|
||
<script class="code"> | ||
function startVideo() { | ||
var url = "https://dash.akamaized.net/akamai/test/caption_test/ElephantsDream/elephants_dream_480p_heaac5_1.mpd", | ||
video = document.querySelector(".dash-video-player video"), | ||
player; | ||
|
||
player = dashjs.MediaPlayer({}).create(); | ||
player.initialize(video, url, true); | ||
player.setTextDefaultEnabled(true); | ||
|
||
var mediaInfo = { | ||
id: 1, | ||
lang: 'en-US', | ||
index: null, | ||
type: null, | ||
streamInfo: null, | ||
representationCount: 0, | ||
viewpoint: null, | ||
roles: [], | ||
codec: null, | ||
mimeType: null, | ||
contentProtection: null, | ||
isText: true, | ||
KID: null, | ||
bitrateList: null, | ||
} | ||
|
||
player.on(dashjs.MediaPlayer.events['STREAM_INITIALIZED'], function handleEvent(e) { | ||
// Relative URL used here -- absolute URLs are also supported | ||
player.addTextTrack('external-captions.vtt', mediaInfo); | ||
}); | ||
} | ||
</script> | ||
|
||
<style> | ||
video { | ||
width: 640px; | ||
height: 360px; | ||
} | ||
</style> | ||
|
||
<body onload="startVideo()"> | ||
<div class="dash-video-player"> | ||
<video controls="true"></video> | ||
</div> | ||
</body> | ||
<script src="../highlighter.js"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
WEBVTT | ||
|
||
00:00:00.500 --> 00:00:04.000 | ||
These are example captions in the VTT format | ||
|
||
00:00:04.500 --> 00:00:08.300 | ||
They are not listed in the manifest file | ||
|
||
00:00:010.000 --> 00:00:14.000 | ||
This is the last caption. Enjoy! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/** | ||
* The copyright in this software is being made available under the BSD License, | ||
* included below. This software may be subject to other third party and contributor | ||
* rights, including patent rights, and no such rights are granted under this license. | ||
* | ||
* Copyright (c) 2013, Dash Industry Forum. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation and/or | ||
* other materials provided with the distribution. | ||
* * Neither the name of Dash Industry Forum nor the names of its | ||
* contributors may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
import Constants from './constants/Constants'; | ||
import DashConstants from '../dash/constants/DashConstants'; | ||
import URLLoader from './net/URLLoader'; | ||
import URLUtils from './utils/URLUtils'; | ||
import TextRequest from './vo/TextRequest'; | ||
import DashJSError from './vo/DashJSError'; | ||
import {HTTPRequest} from './vo/metrics/HTTPRequest'; | ||
import EventBus from '../core/EventBus'; | ||
import Events from '../core/events/Events'; | ||
import Errors from '../core/errors/Errors'; | ||
import FactoryMaker from '../core/FactoryMaker'; | ||
import VTTParser from './utils/VTTParser'; | ||
|
||
function CaptionsLoader(config) { | ||
|
||
config = config || {}; | ||
const context = this.context; | ||
const debug = config.debug; | ||
const eventBus = EventBus(context).getInstance(); | ||
const urlUtils = URLUtils(context).getInstance(); | ||
|
||
let instance, | ||
logger, | ||
urlLoader, | ||
parser; | ||
|
||
let mssHandler = config.mssHandler; | ||
let errHandler = config.errHandler; | ||
|
||
function setup() { | ||
logger = debug.getLogger(instance); | ||
|
||
urlLoader = URLLoader(context).create({ | ||
errHandler: config.errHandler, | ||
dashMetrics: config.dashMetrics, | ||
mediaPlayerModel: config.mediaPlayerModel, | ||
requestModifier: config.requestModifier, | ||
useFetch: config.settings.get().streaming.lowLatencyEnabled, | ||
urlUtils: urlUtils, | ||
constants: Constants, | ||
dashConstants: DashConstants, | ||
errors: Errors | ||
}); | ||
} | ||
|
||
function createParser(data) { | ||
if (data.indexOf('WEBVTT') > -1) { | ||
return VTTParser(context).getInstance(); | ||
} | ||
// } else if (data.indexOf('MPD') > -1 || data.indexOf('Patch') > -1) { | ||
// return DashParser(context).create({debug: debug}); | ||
// } else { | ||
// return parser; | ||
// } | ||
return null; | ||
} | ||
|
||
function load(url) { | ||
|
||
const request = new TextRequest(url, HTTPRequest.MEDIA_SEGMENT_TYPE); | ||
|
||
urlLoader.load({ | ||
request: request, | ||
success: function (data, textStatus, responseURL) { | ||
let actualUrl, | ||
captions; | ||
|
||
// Handle redirects for the MPD - as per RFC3986 Section 5.1.3 | ||
// also handily resolves relative MPD URLs to absolute | ||
if (responseURL && responseURL !== url) { | ||
actualUrl = responseURL; | ||
} else { | ||
// usually this case will be caught and resolved by | ||
// responseURL above but it is not available for IE11 and Edge/12 and Edge/13 | ||
if (urlUtils.isRelative(url)) { | ||
url = urlUtils.resolve(url, window.location.href); | ||
} | ||
} | ||
|
||
// A response of no content implies in-memory is properly up to date | ||
if (textStatus == 'No Content') { | ||
return; | ||
} | ||
|
||
// Create parser according to captions type | ||
parser = createParser(data); | ||
|
||
if (parser === null) { | ||
eventBus.trigger(Events.EXTERNAL_CAPTIONS_LOADED, { | ||
captions: null, | ||
error: new DashJSError( | ||
Errors.CAPTIONS_LOADER_PARSING_FAILURE_ERROR_CODE, | ||
Errors.CAPTIONS_LOADER_PARSING_FAILURE_ERROR_MESSAGE + `${url}` | ||
) | ||
}); | ||
return; | ||
} | ||
|
||
try { | ||
captions = parser.parse(data, 0); | ||
} catch (e) { | ||
errHandler.error(new DashJSError(Errors.TIMED_TEXT_ERROR_ID_PARSE_CODE, Errors.TIMED_TEXT_ERROR_MESSAGE_PARSE + e.message, data)); | ||
} | ||
|
||
if (captions) { | ||
eventBus.trigger(Events.EXTERNAL_CAPTIONS_LOADED, { captions: captions }); | ||
} else { | ||
eventBus.trigger(Events.EXTERNAL_CAPTIONS_LOADED, { | ||
captions: null, | ||
error: new DashJSError( | ||
Errors.CAPTIONS_LOADER_PARSING_FAILURE_ERROR_CODE, | ||
Errors.CAPTIONS_LOADER_PARSING_FAILURE_ERROR_MESSAGE + `${url}` | ||
) | ||
}); | ||
} | ||
}, | ||
error: function (request, statusText, errorText) { | ||
eventBus.trigger(Events.EXTERNAL_CAPTIONS_LOADED, { | ||
captions: null, | ||
error: new DashJSError( | ||
Errors.CAPTIONS_LOADER_LOADING_FAILURE_ERROR_CODE, | ||
Errors.CAPTIONS_LOADER_LOADING_FAILURE_ERROR_MESSAGE + `${url}, ${errorText}` | ||
) | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function reset() { | ||
if (urlLoader) { | ||
urlLoader.abort(); | ||
urlLoader = null; | ||
} | ||
|
||
if (mssHandler) { | ||
mssHandler.reset(); | ||
} | ||
} | ||
|
||
instance = { | ||
load: load, | ||
reset: reset | ||
}; | ||
|
||
setup(); | ||
|
||
return instance; | ||
} | ||
|
||
CaptionsLoader.__dashjs_factory_name = 'CaptionsLoader'; | ||
|
||
const factory = FactoryMaker.getClassFactory(CaptionsLoader); | ||
export default factory; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 97006db