create-text-tracks-if-necessary.js.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: create-text-tracks-if-necessary.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: create-text-tracks-if-necessary.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * @file create-text-tracks-if-necessary.js
  21. */
  22. /**
  23. * Create text tracks on video.js if they exist on a segment.
  24. *
  25. * @param {Object} sourceBuffer the VSB or FSB
  26. * @param {Object} mediaSource the HTML or Flash media source
  27. * @param {Object} segment the segment that may contain the text track
  28. * @private
  29. */
  30. const createTextTracksIfNecessary = function(sourceBuffer, mediaSource, segment) {
  31. const player = mediaSource.player_;
  32. // create an in-band caption track if one is present in the segment
  33. if (segment.captions &amp;&amp;
  34. segment.captions.length) {
  35. if (!sourceBuffer.inbandTextTracks_) {
  36. sourceBuffer.inbandTextTracks_ = {};
  37. }
  38. for (let trackId in segment.captionStreams) {
  39. if (!sourceBuffer.inbandTextTracks_[trackId]) {
  40. player.tech_.trigger({type: 'usage', name: 'hls-608'});
  41. let track = player.textTracks().getTrackById(trackId);
  42. if (track) {
  43. // Resuse an existing track with a CC# id because this was
  44. // very likely created by videojs-contrib-hls from information
  45. // in the m3u8 for us to use
  46. sourceBuffer.inbandTextTracks_[trackId] = track;
  47. } else {
  48. // Otherwise, create a track with the default `CC#` label and
  49. // without a language
  50. sourceBuffer.inbandTextTracks_[trackId] = player.addRemoteTextTrack({
  51. kind: 'captions',
  52. id: trackId,
  53. label: trackId
  54. }, false).track;
  55. }
  56. }
  57. }
  58. }
  59. if (segment.metadata &amp;&amp;
  60. segment.metadata.length &amp;&amp;
  61. !sourceBuffer.metadataTrack_) {
  62. sourceBuffer.metadataTrack_ = player.addRemoteTextTrack({
  63. kind: 'metadata',
  64. label: 'Timed Metadata'
  65. }, false).track;
  66. sourceBuffer.metadataTrack_.inBandMetadataTrackDispatchType =
  67. segment.metadata.dispatchType;
  68. }
  69. };
  70. export default createTextTracksIfNecessary;
  71. </code></pre>
  72. </article>
  73. </section>
  74. </div>
  75. <nav>
  76. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FlashMediaSource.html">FlashMediaSource</a></li><li><a href="FlashSourceBuffer.html">FlashSourceBuffer</a></li><li><a href="HtmlMediaSource.html">HtmlMediaSource</a></li><li><a href="MessageHandlers.html">MessageHandlers</a></li><li><a href="VirtualSourceBuffer.html">VirtualSourceBuffer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#abort">abort</a></li><li><a href="global.html#addSourceBuffer">addSourceBuffer</a></li><li><a href="global.html#appendBuffer">appendBuffer</a></li><li><a href="global.html#appendGopInfo_">appendGopInfo_</a></li><li><a href="global.html#endOfStream">endOfStream</a></li><li><a href="global.html#FlashTransmuxerWorker">FlashTransmuxerWorker</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#gopsSafeToAlignWith">gopsSafeToAlignWith</a></li><li><a href="global.html#MediaSource">MediaSource</a></li><li><a href="global.html#open">open</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#removeGopBuffer">removeGopBuffer</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#supportsNativeMediaSources">supportsNativeMediaSources</a></li><li><a href="global.html#TransmuxerWorker">TransmuxerWorker</a></li><li><a href="global.html#updateGopBuffer">updateGopBuffer</a></li><li><a href="global.html#URL">URL</a></li></ul>
  77. </nav>
  78. <br class="clear">
  79. <footer>
  80. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.4</a> on Thu Nov 02 2017 12:03:25 GMT-0400 (EDT)
  81. </footer>
  82. <script> prettyPrint(); </script>
  83. <script src="scripts/linenumber.js"> </script>
  84. </body>
  85. </html>