rx-player 4.0.0-dev.2023111400 → 4.0.0-dev.2023121900

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/CHANGELOG.md +20 -60
  2. package/FILES.md +1 -1
  3. package/README.md +2 -33
  4. package/VERSION +1 -1
  5. package/dist/_esm5.processed/core/api/debug/buffer_graph.js +2 -6
  6. package/dist/_esm5.processed/core/api/debug/modules/general_info.js +20 -10
  7. package/dist/_esm5.processed/core/api/option_utils.d.ts +0 -2
  8. package/dist/_esm5.processed/core/api/option_utils.js +0 -6
  9. package/dist/_esm5.processed/core/api/public_api.d.ts +1 -2
  10. package/dist/_esm5.processed/core/api/public_api.js +9 -17
  11. package/dist/_esm5.processed/core/init/directfile_content_initializer.js +1 -1
  12. package/dist/_esm5.processed/core/init/media_source_content_initializer.js +3 -14
  13. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.d.ts +2 -36
  14. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.js +2 -82
  15. package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
  16. package/dist/_esm5.processed/core/segment_buffers/implementations/image/image_segment_buffer.js +1 -1
  17. package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
  18. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
  19. package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
  20. package/dist/_esm5.processed/core/segment_buffers/inventory/index.d.ts +2 -2
  21. package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
  22. package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.js +19 -10
  23. package/dist/_esm5.processed/core/stream/representation/utils/get_buffer_status.js +1 -1
  24. package/dist/_esm5.processed/core/stream/representation/utils/get_needed_segments.js +1 -1
  25. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_extent.js +1 -8
  26. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
  27. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_origin.js +1 -9
  28. package/dist/_esm5.processed/public_types.d.ts +2 -0
  29. package/dist/commonjs/compat/is_codec_supported.js +22 -1
  30. package/dist/commonjs/config.d.ts +2 -1
  31. package/dist/commonjs/core/adaptive/adaptive_representation_selector.d.ts +2 -19
  32. package/dist/commonjs/core/adaptive/adaptive_representation_selector.js +2 -2
  33. package/dist/commonjs/core/adaptive/network_analyzer.js +3 -3
  34. package/dist/commonjs/core/api/debug/buffer_graph.js +2 -6
  35. package/dist/commonjs/core/api/debug/modules/general_info.js +17 -10
  36. package/dist/commonjs/core/api/index.d.ts +1 -1
  37. package/dist/commonjs/core/api/option_utils.d.ts +2 -0
  38. package/dist/commonjs/core/api/option_utils.js +2 -3
  39. package/dist/commonjs/core/api/playback_observer.d.ts +128 -8
  40. package/dist/commonjs/core/api/playback_observer.js +217 -64
  41. package/dist/commonjs/core/api/public_api.d.ts +9 -0
  42. package/dist/commonjs/core/api/public_api.js +41 -16
  43. package/dist/commonjs/core/api/utils.js +1 -1
  44. package/dist/commonjs/core/decrypt/get_media_keys.js +2 -6
  45. package/dist/commonjs/core/fetchers/manifest/manifest_fetcher.d.ts +6 -0
  46. package/dist/commonjs/core/fetchers/manifest/manifest_fetcher.js +11 -3
  47. package/dist/commonjs/core/fetchers/segment/segment_fetcher.d.ts +8 -1
  48. package/dist/commonjs/core/fetchers/segment/segment_fetcher.js +8 -4
  49. package/dist/commonjs/core/fetchers/segment/segment_fetcher_creator.d.ts +1 -0
  50. package/dist/commonjs/core/fetchers/utils/schedule_request.js +1 -1
  51. package/dist/commonjs/core/init/directfile_content_initializer.js +29 -8
  52. package/dist/commonjs/core/init/media_source_content_initializer.d.ts +6 -0
  53. package/dist/commonjs/core/init/media_source_content_initializer.js +32 -20
  54. package/dist/commonjs/core/init/utils/content_time_boundaries_observer.d.ts +13 -12
  55. package/dist/commonjs/core/init/utils/content_time_boundaries_observer.js +17 -19
  56. package/dist/commonjs/core/init/utils/create_stream_playback_observer.d.ts +1 -5
  57. package/dist/commonjs/core/init/utils/create_stream_playback_observer.js +16 -14
  58. package/dist/commonjs/core/init/utils/get_initial_time.d.ts +17 -3
  59. package/dist/commonjs/core/init/utils/get_initial_time.js +9 -7
  60. package/dist/commonjs/core/init/utils/initial_seek_and_play.d.ts +9 -11
  61. package/dist/commonjs/core/init/utils/initial_seek_and_play.js +121 -91
  62. package/dist/commonjs/core/init/utils/rebuffering_controller.js +27 -70
  63. package/dist/commonjs/core/init/utils/stream_events_emitter/stream_events_emitter.js +4 -2
  64. package/dist/commonjs/core/segment_buffers/garbage_collector.js +1 -2
  65. package/dist/commonjs/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
  66. package/dist/commonjs/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
  67. package/dist/commonjs/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
  68. package/dist/commonjs/core/segment_buffers/index.d.ts +2 -2
  69. package/dist/commonjs/core/segment_buffers/inventory/index.d.ts +2 -2
  70. package/dist/commonjs/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
  71. package/dist/commonjs/core/segment_buffers/inventory/segment_inventory.js +19 -10
  72. package/dist/commonjs/core/stream/adaptation/get_representations_switch_strategy.d.ts +2 -2
  73. package/dist/commonjs/core/stream/adaptation/get_representations_switch_strategy.js +16 -9
  74. package/dist/commonjs/core/stream/orchestrator/stream_orchestrator.js +14 -18
  75. package/dist/commonjs/core/stream/period/period_stream.js +5 -8
  76. package/dist/commonjs/core/stream/period/types.d.ts +2 -3
  77. package/dist/commonjs/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +4 -5
  78. package/dist/commonjs/core/stream/period/utils/get_adaptation_switch_strategy.js +17 -13
  79. package/dist/commonjs/core/stream/representation/representation_stream.js +3 -4
  80. package/dist/commonjs/core/stream/representation/types.d.ts +2 -2
  81. package/dist/commonjs/core/stream/representation/utils/append_segment_to_buffer.js +11 -12
  82. package/dist/commonjs/core/stream/representation/utils/get_buffer_status.js +4 -4
  83. package/dist/commonjs/core/stream/representation/utils/get_needed_segments.js +1 -1
  84. package/dist/commonjs/default_config.d.ts +12 -16
  85. package/dist/commonjs/default_config.js +21 -16
  86. package/dist/commonjs/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -1
  87. package/dist/commonjs/experimental/tools/createMetaplaylist/get_duration_from_manifest.js +2 -0
  88. package/dist/commonjs/manifest/adaptation.js +2 -1
  89. package/dist/commonjs/manifest/representation_index/static.d.ts +1 -1
  90. package/dist/commonjs/manifest/representation_index/static.js +2 -2
  91. package/dist/commonjs/manifest/representation_index/types.d.ts +4 -4
  92. package/dist/commonjs/parsers/manifest/dash/common/indexes/base.d.ts +6 -1
  93. package/dist/commonjs/parsers/manifest/dash/common/indexes/base.js +4 -3
  94. package/dist/commonjs/parsers/manifest/dash/common/indexes/get_segments_from_timeline.d.ts +5 -2
  95. package/dist/commonjs/parsers/manifest/dash/common/indexes/get_segments_from_timeline.js +15 -4
  96. package/dist/commonjs/parsers/manifest/dash/common/indexes/index.d.ts +5 -5
  97. package/dist/commonjs/parsers/manifest/dash/common/indexes/list.d.ts +1 -1
  98. package/dist/commonjs/parsers/manifest/dash/common/indexes/list.js +2 -2
  99. package/dist/commonjs/parsers/manifest/dash/common/indexes/template.d.ts +12 -5
  100. package/dist/commonjs/parsers/manifest/dash/common/indexes/template.js +42 -29
  101. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/index.d.ts +2 -1
  102. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +99 -6
  103. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +250 -51
  104. package/dist/commonjs/parsers/manifest/dash/common/manifest_bounds_calculator.d.ts +40 -17
  105. package/dist/commonjs/parsers/manifest/dash/common/manifest_bounds_calculator.js +38 -18
  106. package/dist/commonjs/parsers/manifest/dash/common/parse_adaptation_sets.js +13 -10
  107. package/dist/commonjs/parsers/manifest/dash/common/parse_mpd.js +27 -14
  108. package/dist/commonjs/parsers/manifest/dash/common/parse_periods.d.ts +1 -1
  109. package/dist/commonjs/parsers/manifest/dash/common/parse_periods.js +17 -18
  110. package/dist/commonjs/parsers/manifest/dash/common/parse_representation_index.d.ts +19 -6
  111. package/dist/commonjs/parsers/manifest/dash/common/parse_representation_index.js +21 -8
  112. package/dist/commonjs/parsers/manifest/dash/common/parse_representations.js +7 -3
  113. package/dist/commonjs/parsers/manifest/local/representation_index.d.ts +1 -1
  114. package/dist/commonjs/parsers/manifest/local/representation_index.js +3 -3
  115. package/dist/commonjs/parsers/manifest/metaplaylist/representation_index.d.ts +1 -1
  116. package/dist/commonjs/parsers/manifest/metaplaylist/representation_index.js +2 -2
  117. package/dist/commonjs/parsers/manifest/smooth/representation_index.d.ts +5 -5
  118. package/dist/commonjs/parsers/manifest/smooth/representation_index.js +25 -9
  119. package/dist/commonjs/parsers/manifest/utils/index_helpers.js +1 -1
  120. package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
  121. package/dist/commonjs/public_types.d.ts +107 -36
  122. package/dist/commonjs/transports/dash/init_segment_loader.js +10 -5
  123. package/dist/commonjs/transports/dash/manifest_parser.js +5 -2
  124. package/dist/commonjs/transports/dash/segment_loader.js +2 -1
  125. package/dist/commonjs/transports/dash/text_loader.js +2 -0
  126. package/dist/commonjs/transports/metaplaylist/manifest_loader.js +2 -1
  127. package/dist/commonjs/transports/metaplaylist/pipelines.js +4 -1
  128. package/dist/commonjs/transports/smooth/pipelines.js +4 -2
  129. package/dist/commonjs/transports/smooth/segment_loader.js +2 -1
  130. package/dist/commonjs/transports/types.d.ts +12 -0
  131. package/dist/commonjs/transports/utils/generate_manifest_loader.js +6 -3
  132. package/dist/commonjs/utils/request/fetch.d.ts +6 -0
  133. package/dist/commonjs/utils/request/fetch.js +29 -8
  134. package/dist/commonjs/utils/request/xhr.d.ts +11 -5
  135. package/dist/commonjs/utils/request/xhr.js +29 -8
  136. package/dist/es2017/compat/is_codec_supported.js +22 -1
  137. package/dist/es2017/config.d.ts +2 -1
  138. package/dist/es2017/core/adaptive/adaptive_representation_selector.d.ts +2 -19
  139. package/dist/es2017/core/adaptive/adaptive_representation_selector.js +2 -2
  140. package/dist/es2017/core/adaptive/network_analyzer.js +3 -3
  141. package/dist/es2017/core/api/debug/buffer_graph.js +2 -6
  142. package/dist/es2017/core/api/debug/modules/general_info.js +17 -10
  143. package/dist/es2017/core/api/index.d.ts +1 -1
  144. package/dist/es2017/core/api/option_utils.d.ts +2 -0
  145. package/dist/es2017/core/api/option_utils.js +2 -3
  146. package/dist/es2017/core/api/playback_observer.d.ts +128 -8
  147. package/dist/es2017/core/api/playback_observer.js +217 -66
  148. package/dist/es2017/core/api/public_api.d.ts +9 -0
  149. package/dist/es2017/core/api/public_api.js +40 -15
  150. package/dist/es2017/core/api/utils.js +1 -1
  151. package/dist/es2017/core/decrypt/get_media_keys.js +2 -6
  152. package/dist/es2017/core/fetchers/manifest/manifest_fetcher.d.ts +6 -0
  153. package/dist/es2017/core/fetchers/manifest/manifest_fetcher.js +11 -3
  154. package/dist/es2017/core/fetchers/segment/segment_fetcher.d.ts +8 -1
  155. package/dist/es2017/core/fetchers/segment/segment_fetcher.js +8 -4
  156. package/dist/es2017/core/fetchers/segment/segment_fetcher_creator.d.ts +1 -0
  157. package/dist/es2017/core/fetchers/utils/schedule_request.js +1 -1
  158. package/dist/es2017/core/init/directfile_content_initializer.js +31 -8
  159. package/dist/es2017/core/init/media_source_content_initializer.d.ts +6 -0
  160. package/dist/es2017/core/init/media_source_content_initializer.js +34 -22
  161. package/dist/es2017/core/init/utils/content_time_boundaries_observer.d.ts +13 -12
  162. package/dist/es2017/core/init/utils/content_time_boundaries_observer.js +17 -17
  163. package/dist/es2017/core/init/utils/create_stream_playback_observer.d.ts +1 -5
  164. package/dist/es2017/core/init/utils/create_stream_playback_observer.js +16 -14
  165. package/dist/es2017/core/init/utils/get_initial_time.d.ts +17 -3
  166. package/dist/es2017/core/init/utils/get_initial_time.js +9 -7
  167. package/dist/es2017/core/init/utils/initial_seek_and_play.d.ts +9 -11
  168. package/dist/es2017/core/init/utils/initial_seek_and_play.js +120 -91
  169. package/dist/es2017/core/init/utils/rebuffering_controller.js +27 -70
  170. package/dist/es2017/core/init/utils/stream_events_emitter/stream_events_emitter.js +4 -2
  171. package/dist/es2017/core/segment_buffers/garbage_collector.js +1 -2
  172. package/dist/es2017/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
  173. package/dist/es2017/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
  174. package/dist/es2017/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
  175. package/dist/es2017/core/segment_buffers/index.d.ts +2 -2
  176. package/dist/es2017/core/segment_buffers/inventory/index.d.ts +2 -2
  177. package/dist/es2017/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
  178. package/dist/es2017/core/segment_buffers/inventory/segment_inventory.js +19 -10
  179. package/dist/es2017/core/stream/adaptation/get_representations_switch_strategy.d.ts +2 -2
  180. package/dist/es2017/core/stream/adaptation/get_representations_switch_strategy.js +16 -9
  181. package/dist/es2017/core/stream/orchestrator/stream_orchestrator.js +16 -18
  182. package/dist/es2017/core/stream/period/period_stream.js +4 -7
  183. package/dist/es2017/core/stream/period/types.d.ts +2 -3
  184. package/dist/es2017/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +4 -5
  185. package/dist/es2017/core/stream/period/utils/get_adaptation_switch_strategy.js +17 -13
  186. package/dist/es2017/core/stream/representation/representation_stream.js +3 -4
  187. package/dist/es2017/core/stream/representation/types.d.ts +2 -2
  188. package/dist/es2017/core/stream/representation/utils/append_segment_to_buffer.js +1 -2
  189. package/dist/es2017/core/stream/representation/utils/get_buffer_status.js +4 -4
  190. package/dist/es2017/core/stream/representation/utils/get_needed_segments.js +1 -1
  191. package/dist/es2017/default_config.d.ts +12 -16
  192. package/dist/es2017/default_config.js +21 -16
  193. package/dist/es2017/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -1
  194. package/dist/es2017/experimental/tools/createMetaplaylist/get_duration_from_manifest.js +2 -0
  195. package/dist/es2017/manifest/adaptation.js +2 -1
  196. package/dist/es2017/manifest/representation_index/static.d.ts +1 -1
  197. package/dist/es2017/manifest/representation_index/static.js +2 -2
  198. package/dist/es2017/manifest/representation_index/types.d.ts +4 -4
  199. package/dist/es2017/parsers/manifest/dash/common/indexes/base.d.ts +6 -1
  200. package/dist/es2017/parsers/manifest/dash/common/indexes/base.js +4 -3
  201. package/dist/es2017/parsers/manifest/dash/common/indexes/get_segments_from_timeline.d.ts +5 -2
  202. package/dist/es2017/parsers/manifest/dash/common/indexes/get_segments_from_timeline.js +15 -4
  203. package/dist/es2017/parsers/manifest/dash/common/indexes/index.d.ts +5 -5
  204. package/dist/es2017/parsers/manifest/dash/common/indexes/list.d.ts +1 -1
  205. package/dist/es2017/parsers/manifest/dash/common/indexes/list.js +2 -2
  206. package/dist/es2017/parsers/manifest/dash/common/indexes/template.d.ts +12 -5
  207. package/dist/es2017/parsers/manifest/dash/common/indexes/template.js +40 -27
  208. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/index.d.ts +2 -1
  209. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +99 -6
  210. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +246 -51
  211. package/dist/es2017/parsers/manifest/dash/common/manifest_bounds_calculator.d.ts +40 -17
  212. package/dist/es2017/parsers/manifest/dash/common/manifest_bounds_calculator.js +38 -18
  213. package/dist/es2017/parsers/manifest/dash/common/parse_adaptation_sets.js +11 -8
  214. package/dist/es2017/parsers/manifest/dash/common/parse_mpd.js +27 -13
  215. package/dist/es2017/parsers/manifest/dash/common/parse_periods.d.ts +1 -1
  216. package/dist/es2017/parsers/manifest/dash/common/parse_periods.js +13 -16
  217. package/dist/es2017/parsers/manifest/dash/common/parse_representation_index.d.ts +19 -6
  218. package/dist/es2017/parsers/manifest/dash/common/parse_representation_index.js +10 -8
  219. package/dist/es2017/parsers/manifest/dash/common/parse_representations.js +7 -3
  220. package/dist/es2017/parsers/manifest/local/representation_index.d.ts +1 -1
  221. package/dist/es2017/parsers/manifest/local/representation_index.js +3 -3
  222. package/dist/es2017/parsers/manifest/metaplaylist/representation_index.d.ts +1 -1
  223. package/dist/es2017/parsers/manifest/metaplaylist/representation_index.js +2 -2
  224. package/dist/es2017/parsers/manifest/smooth/representation_index.d.ts +5 -5
  225. package/dist/es2017/parsers/manifest/smooth/representation_index.js +25 -9
  226. package/dist/es2017/parsers/manifest/utils/index_helpers.js +1 -1
  227. package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
  228. package/dist/es2017/public_types.d.ts +107 -36
  229. package/dist/es2017/transports/dash/init_segment_loader.js +5 -0
  230. package/dist/es2017/transports/dash/manifest_parser.js +3 -0
  231. package/dist/es2017/transports/dash/segment_loader.js +1 -0
  232. package/dist/es2017/transports/dash/text_loader.js +2 -0
  233. package/dist/es2017/transports/metaplaylist/manifest_loader.js +1 -0
  234. package/dist/es2017/transports/metaplaylist/pipelines.js +4 -1
  235. package/dist/es2017/transports/smooth/pipelines.js +2 -0
  236. package/dist/es2017/transports/smooth/segment_loader.js +1 -0
  237. package/dist/es2017/transports/types.d.ts +12 -0
  238. package/dist/es2017/transports/utils/generate_manifest_loader.js +3 -0
  239. package/dist/es2017/utils/request/fetch.d.ts +6 -0
  240. package/dist/es2017/utils/request/fetch.js +29 -8
  241. package/dist/es2017/utils/request/xhr.d.ts +11 -5
  242. package/dist/es2017/utils/request/xhr.js +30 -9
  243. package/dist/mpd-parser.wasm +0 -0
  244. package/dist/rx-player.js +1335 -812
  245. package/dist/rx-player.min.js +1 -1
  246. package/package.json +7 -4
  247. package/scripts/canal-release.patch +78 -0
  248. package/scripts/make-dev-releases +65 -0
  249. package/scripts/update-version +7 -0
  250. package/sonar-project.properties +1 -1
  251. package/src/compat/is_codec_supported.ts +23 -1
  252. package/src/core/adaptive/adaptive_representation_selector.ts +4 -21
  253. package/src/core/adaptive/network_analyzer.ts +3 -3
  254. package/src/core/api/debug/buffer_graph.ts +2 -5
  255. package/src/core/api/debug/modules/general_info.ts +15 -10
  256. package/src/core/api/index.ts +1 -0
  257. package/src/core/api/option_utils.ts +3 -3
  258. package/src/core/api/playback_observer.ts +327 -107
  259. package/src/core/api/public_api.ts +42 -14
  260. package/src/core/api/utils.ts +3 -1
  261. package/src/core/decrypt/get_media_keys.ts +2 -8
  262. package/src/core/fetchers/manifest/manifest_fetcher.ts +21 -3
  263. package/src/core/fetchers/segment/segment_fetcher.ts +19 -5
  264. package/src/core/fetchers/segment/segment_fetcher_creator.ts +1 -0
  265. package/src/core/fetchers/utils/schedule_request.ts +1 -1
  266. package/src/core/init/directfile_content_initializer.ts +31 -15
  267. package/src/core/init/media_source_content_initializer.ts +40 -27
  268. package/src/core/init/utils/content_time_boundaries_observer.ts +24 -23
  269. package/src/core/init/utils/create_stream_playback_observer.ts +19 -20
  270. package/src/core/init/utils/get_initial_time.ts +25 -12
  271. package/src/core/init/utils/initial_seek_and_play.ts +140 -108
  272. package/src/core/init/utils/rebuffering_controller.ts +32 -77
  273. package/src/core/init/utils/stream_events_emitter/stream_events_emitter.ts +5 -2
  274. package/src/core/segment_buffers/garbage_collector.ts +1 -1
  275. package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +10 -2
  276. package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +1 -1
  277. package/src/core/segment_buffers/implementations/text/native/native_text_segment_buffer.ts +1 -1
  278. package/src/core/segment_buffers/index.ts +2 -0
  279. package/src/core/segment_buffers/inventory/index.ts +2 -0
  280. package/src/core/segment_buffers/inventory/segment_inventory.ts +49 -17
  281. package/src/core/stream/adaptation/get_representations_switch_strategy.ts +21 -12
  282. package/src/core/stream/orchestrator/stream_orchestrator.ts +14 -19
  283. package/src/core/stream/period/period_stream.ts +7 -8
  284. package/src/core/stream/period/types.ts +2 -3
  285. package/src/core/stream/period/utils/get_adaptation_switch_strategy.ts +21 -15
  286. package/src/core/stream/representation/representation_stream.ts +3 -5
  287. package/src/core/stream/representation/types.ts +2 -2
  288. package/src/core/stream/representation/utils/append_segment_to_buffer.ts +1 -1
  289. package/src/core/stream/representation/utils/get_buffer_status.ts +5 -4
  290. package/src/core/stream/representation/utils/get_needed_segments.ts +2 -2
  291. package/src/default_config.ts +22 -17
  292. package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +3 -1
  293. package/src/experimental/tools/createMetaplaylist/get_duration_from_manifest.ts +2 -0
  294. package/src/manifest/adaptation.ts +2 -1
  295. package/src/manifest/representation_index/static.ts +2 -2
  296. package/src/manifest/representation_index/types.ts +4 -4
  297. package/src/parsers/manifest/dash/common/__tests__/manifest_bounds_calculator.test.ts +182 -36
  298. package/src/parsers/manifest/dash/common/indexes/base.ts +12 -4
  299. package/src/parsers/manifest/dash/common/indexes/get_segments_from_timeline.ts +19 -5
  300. package/src/parsers/manifest/dash/common/indexes/index.ts +16 -4
  301. package/src/parsers/manifest/dash/common/indexes/list.ts +2 -2
  302. package/src/parsers/manifest/dash/common/indexes/template.ts +52 -31
  303. package/src/parsers/manifest/dash/common/indexes/timeline/index.ts +4 -1
  304. package/src/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.ts +366 -60
  305. package/src/parsers/manifest/dash/common/manifest_bounds_calculator.ts +63 -25
  306. package/src/parsers/manifest/dash/common/parse_adaptation_sets.ts +10 -4
  307. package/src/parsers/manifest/dash/common/parse_mpd.ts +28 -15
  308. package/src/parsers/manifest/dash/common/parse_periods.ts +12 -17
  309. package/src/parsers/manifest/dash/common/parse_representation_index.ts +50 -26
  310. package/src/parsers/manifest/dash/common/parse_representations.ts +9 -3
  311. package/src/parsers/manifest/local/representation_index.ts +3 -3
  312. package/src/parsers/manifest/metaplaylist/representation_index.ts +2 -2
  313. package/src/parsers/manifest/smooth/representation_index.ts +23 -9
  314. package/src/parsers/manifest/utils/__tests__/get_first_time_from_adaptations.test.ts +1 -1
  315. package/src/parsers/manifest/utils/__tests__/get_last_time_from_adaptation.test.ts +1 -1
  316. package/src/parsers/manifest/utils/index_helpers.ts +1 -1
  317. package/src/parsers/texttracks/ttml/html/apply_line_height.ts +3 -1
  318. package/src/public_types.ts +108 -36
  319. package/src/transports/dash/init_segment_loader.ts +5 -0
  320. package/src/transports/dash/manifest_parser.ts +6 -0
  321. package/src/transports/dash/segment_loader.ts +1 -0
  322. package/src/transports/dash/text_loader.ts +2 -0
  323. package/src/transports/metaplaylist/manifest_loader.ts +1 -0
  324. package/src/transports/metaplaylist/pipelines.ts +4 -1
  325. package/src/transports/smooth/pipelines.ts +2 -0
  326. package/src/transports/smooth/segment_loader.ts +1 -0
  327. package/src/transports/types.ts +12 -0
  328. package/src/transports/utils/generate_manifest_loader.ts +3 -0
  329. package/src/utils/request/fetch.ts +35 -8
  330. package/src/utils/request/xhr.ts +45 -14
  331. package/dist/commonjs/parsers/manifest/utils/is_segment_still_available.d.ts +0 -29
  332. package/dist/commonjs/parsers/manifest/utils/is_segment_still_available.js +0 -54
  333. package/dist/es2017/parsers/manifest/utils/is_segment_still_available.d.ts +0 -29
  334. package/dist/es2017/parsers/manifest/utils/is_segment_still_available.js +0 -51
  335. package/src/parsers/manifest/utils/is_segment_still_available.ts +0 -58
  336. package/src/typings/object-assign.d.ts +0 -48
@@ -49,8 +49,8 @@ var task_canceller_1 = require("../../../utils/task_canceller");
49
49
  /**
50
50
  * Observes what's being played and take care of media events relating to time
51
51
  * boundaries:
52
- * - Emits a `durationUpdate` when the duration of the current content is
53
- * known and every time it changes.
52
+ * - Emits a `endingPositionChange` when the known maximum playable position
53
+ * of the current content is known and every time it changes.
54
54
  * - Emits `endOfStream` API once segments have been pushed until the end and
55
55
  * `resumeStream` if downloads starts back.
56
56
  * - Emits a `periodChange` event when the currently-playing Period seemed to
@@ -80,9 +80,8 @@ var ContentTimeBoundariesObserver = /** @class */ (function (_super) {
80
80
  _this._maximumPositionCalculator = maximumPositionCalculator;
81
81
  var cancelSignal = _this._canceller.signal;
82
82
  playbackObserver.listen(function (_a) {
83
- var _b;
84
83
  var position = _a.position;
85
- var wantedPosition = (_b = position.pending) !== null && _b !== void 0 ? _b : position.last;
84
+ var wantedPosition = position.getWanted();
86
85
  if (wantedPosition < manifest.getMinimumSafePosition()) {
87
86
  var warning = new errors_1.MediaError("MEDIA_TIME_BEFORE_MANIFEST", "The current position is behind the " +
88
87
  "earliest time announced in the Manifest.");
@@ -95,7 +94,7 @@ var ContentTimeBoundariesObserver = /** @class */ (function (_super) {
95
94
  }
96
95
  }, { includeLastObservation: true, clearSignal: cancelSignal });
97
96
  manifest.addEventListener("manifestUpdate", function () {
98
- _this.trigger("durationUpdate", _this._getManifestDuration());
97
+ _this.trigger("endingPositionChange", _this._getManifestEndTime());
99
98
  if (cancelSignal.isCancelled()) {
100
99
  return;
101
100
  }
@@ -104,11 +103,12 @@ var ContentTimeBoundariesObserver = /** @class */ (function (_super) {
104
103
  return _this;
105
104
  }
106
105
  /**
107
- * Returns an estimate of the current duration of the content.
106
+ * Returns an estimate of the current last position which may be played in
107
+ * the content at the moment.
108
108
  * @returns {Object}
109
109
  */
110
- ContentTimeBoundariesObserver.prototype.getCurrentDuration = function () {
111
- return this._getManifestDuration();
110
+ ContentTimeBoundariesObserver.prototype.getCurrentEndingTime = function () {
111
+ return this._getManifestEndTime();
112
112
  };
113
113
  /**
114
114
  * Method to call any time an Adaptation has been selected.
@@ -137,12 +137,12 @@ var ContentTimeBoundariesObserver = /** @class */ (function (_super) {
137
137
  .updateLastVideoAdaptation(adaptation);
138
138
  }
139
139
  var endingPosition = this._maximumPositionCalculator.getEndingPosition();
140
- var newDuration = endingPosition !== undefined ?
141
- { isEnd: true,
142
- duration: endingPosition } :
140
+ var newEndingPosition = endingPosition !== undefined ?
141
+ { isEnd: true, endingPosition: endingPosition } :
143
142
  { isEnd: false,
144
- duration: this._maximumPositionCalculator.getMaximumAvailablePosition() };
145
- this.trigger("durationUpdate", newDuration);
143
+ endingPosition: this._maximumPositionCalculator
144
+ .getMaximumAvailablePosition() };
145
+ this.trigger("endingPositionChange", newEndingPosition);
146
146
  }
147
147
  }
148
148
  }
@@ -286,13 +286,12 @@ var ContentTimeBoundariesObserver = /** @class */ (function (_super) {
286
286
  finally { if (e_1) throw e_1.error; }
287
287
  }
288
288
  };
289
- ContentTimeBoundariesObserver.prototype._getManifestDuration = function () {
289
+ ContentTimeBoundariesObserver.prototype._getManifestEndTime = function () {
290
290
  var endingPosition = this._maximumPositionCalculator.getEndingPosition();
291
291
  return endingPosition !== undefined ?
292
- { isEnd: true,
293
- duration: endingPosition } :
292
+ { isEnd: true, endingPosition: endingPosition } :
294
293
  { isEnd: false,
295
- duration: this._maximumPositionCalculator.getMaximumAvailablePosition() };
294
+ endingPosition: this._maximumPositionCalculator.getMaximumAvailablePosition() };
296
295
  };
297
296
  ContentTimeBoundariesObserver.prototype._lazilyCreateActiveStreamInfo = function (bufferType) {
298
297
  var streamInfo = this._activeStreams.get(bufferType);
@@ -366,9 +365,8 @@ var MaximumPositionCalculator = /** @class */ (function () {
366
365
  * @returns {number}
367
366
  */
368
367
  MaximumPositionCalculator.prototype.getMaximumAvailablePosition = function () {
369
- var _a;
370
368
  if (this._manifest.isDynamic) {
371
- return (_a = this._manifest.getLivePosition()) !== null && _a !== void 0 ? _a : this._manifest.getMaximumSafePosition();
369
+ return this._manifest.getMaximumSafePosition();
372
370
  }
373
371
  if (this._lastVideoAdaptation === undefined ||
374
372
  this._lastAudioAdaptation === undefined) {
@@ -26,12 +26,8 @@ export interface IStreamPlaybackObserverArguments {
26
26
  manifest: Manifest;
27
27
  /** Becomes `true` after the initial play has been taken care of. */
28
28
  initialPlayPerformed: IReadOnlySharedReference<boolean>;
29
- /** Becomes `true` after the initial seek has been taken care of. */
30
- initialSeekPerformed: IReadOnlySharedReference<boolean>;
31
29
  /** The last speed requested by the user. */
32
30
  speed: IReadOnlySharedReference<number>;
33
- /** The time the player will seek when `initialSeekPerformed` becomes `true`. */
34
- startTime: number;
35
31
  }
36
32
  /**
37
33
  * Create PlaybackObserver for the `Stream` part of the code.
@@ -42,4 +38,4 @@ export interface IStreamPlaybackObserverArguments {
42
38
  * @param {Object} fnCancelSignal - Abort the created PlaybackObserver.
43
39
  * @returns {Object}
44
40
  */
45
- export default function createStreamPlaybackObserver(srcPlaybackObserver: PlaybackObserver, { autoPlay, initialPlayPerformed, initialSeekPerformed, manifest, speed, startTime }: IStreamPlaybackObserverArguments, fnCancelSignal: CancellationSignal): IReadOnlyPlaybackObserver<IStreamOrchestratorPlaybackObservation>;
41
+ export default function createStreamPlaybackObserver(srcPlaybackObserver: PlaybackObserver, { autoPlay, initialPlayPerformed, manifest, speed }: IStreamPlaybackObserverArguments, fnCancelSignal: CancellationSignal): IReadOnlyPlaybackObserver<IStreamOrchestratorPlaybackObservation>;
@@ -27,7 +27,7 @@ var task_canceller_1 = require("../../../utils/task_canceller");
27
27
  * @returns {Object}
28
28
  */
29
29
  function createStreamPlaybackObserver(srcPlaybackObserver, _a, fnCancelSignal) {
30
- var autoPlay = _a.autoPlay, initialPlayPerformed = _a.initialPlayPerformed, initialSeekPerformed = _a.initialSeekPerformed, manifest = _a.manifest, speed = _a.speed, startTime = _a.startTime;
30
+ var autoPlay = _a.autoPlay, initialPlayPerformed = _a.initialPlayPerformed, manifest = _a.manifest, speed = _a.speed;
31
31
  return srcPlaybackObserver.deriveReadOnlyObserver(function transform(observationRef, parentObserverCancelSignal) {
32
32
  var canceller = new task_canceller_1.default();
33
33
  canceller.linkToSignal(parentObserverCancelSignal);
@@ -45,11 +45,7 @@ function createStreamPlaybackObserver(srcPlaybackObserver, _a, fnCancelSignal) {
45
45
  function constructStreamPlaybackObservation() {
46
46
  var observation = observationRef.getValue();
47
47
  var lastSpeed = speed.getValue();
48
- var pendingPosition;
49
- if (!initialSeekPerformed.getValue()) {
50
- pendingPosition = startTime;
51
- }
52
- else if (!manifest.isDynamic || manifest.isLastPeriodKnown) {
48
+ if (!manifest.isDynamic || manifest.isLastPeriodKnown) {
53
49
  // HACK: When the position is actually further than the maximum
54
50
  // position for a finished content, we actually want to be loading
55
51
  // the last segment before ending.
@@ -57,19 +53,25 @@ function createStreamPlaybackObserver(srcPlaybackObserver, _a, fnCancelSignal) {
57
53
  // want to seek one second before the period's end (despite never
58
54
  // doing it).
59
55
  var lastPeriod = manifest.periods[manifest.periods.length - 1];
60
- if (lastPeriod !== undefined &&
61
- lastPeriod.end !== undefined &&
62
- observation.position > lastPeriod.end) {
63
- pendingPosition = lastPeriod.end - 1;
56
+ if (lastPeriod !== undefined && lastPeriod.end !== undefined) {
57
+ var wantedPosition = observation.position.getWanted();
58
+ if (wantedPosition >= lastPeriod.start &&
59
+ wantedPosition >= lastPeriod.end - 1) {
60
+ // We're after the end of the last Period, check if `buffered`
61
+ // indicates that the last segment is probably not loaded, in which
62
+ // case act as if we want to load one second before the end.
63
+ var buffered = observation.buffered;
64
+ if (buffered.length === 0 ||
65
+ buffered.end(buffered.length - 1) < observation.duration - 1) {
66
+ observation.position.forceWantedPosition(lastPeriod.end - 1);
67
+ }
68
+ }
64
69
  }
65
70
  }
66
71
  return {
67
72
  // TODO more exact according to the current Adaptation chosen?
68
73
  maximumPosition: manifest.getMaximumSafePosition(),
69
- position: {
70
- last: observation.position,
71
- pending: pendingPosition,
72
- },
74
+ position: observation.position,
73
75
  duration: observation.duration,
74
76
  paused: {
75
77
  last: observation.paused,
@@ -37,11 +37,25 @@ export interface IInitialTimeOptions {
37
37
  */
38
38
  fromFirstPosition?: number | null | undefined;
39
39
  /**
40
- * If set, we should begin at this position relative to the content's end,
41
- * in seconds.
40
+ * If set, we should begin at this position relative to the content's maximum
41
+ * seekable position, in seconds.
42
+ *
43
+ * It should consequently in most cases be a negative value.
42
44
  */
43
45
  fromLastPosition?: number | null | undefined;
44
- /** If set, we should begin at this position relative to the whole duration of
46
+ /**
47
+ * If set, we should begin at this position relative to the content's live
48
+ * edge if it makes sense, in seconds.
49
+ *
50
+ * It should consequently in most cases be a negative value.
51
+ *
52
+ * If the live edge is unknown or if it does not make sense for the current
53
+ * content, that position is relative to the content's maximum position
54
+ * instead.
55
+ */
56
+ fromLivePosition?: number | null | undefined;
57
+ /**
58
+ * If set, we should begin at this position relative to the whole duration of
45
59
  * the content, in percentage.
46
60
  */
47
61
  percentage?: number | null | undefined;
@@ -33,15 +33,10 @@ var monotonic_timestamp_1 = require("../../../utils/monotonic_timestamp");
33
33
  * @returns {Number}
34
34
  */
35
35
  function getInitialTime(manifest, lowLatencyMode, startAt) {
36
+ var _a;
36
37
  if (!(0, is_null_or_undefined_1.default)(startAt)) {
37
38
  var min = manifest.getMinimumSafePosition();
38
- var max = void 0;
39
- if (manifest.isLive) {
40
- max = manifest.getLivePosition();
41
- }
42
- if (max === undefined) {
43
- max = manifest.getMaximumSafePosition();
44
- }
39
+ var max = manifest.getMaximumSafePosition();
45
40
  if (!(0, is_null_or_undefined_1.default)(startAt.position)) {
46
41
  log_1.default.debug("Init: using startAt.minimumPosition");
47
42
  return Math.max(Math.min(startAt.position, max), min);
@@ -66,6 +61,13 @@ function getInitialTime(manifest, lowLatencyMode, startAt) {
66
61
  return fromLastPosition >= 0 ? max :
67
62
  Math.max(min, max + fromLastPosition);
68
63
  }
64
+ else if (!(0, is_null_or_undefined_1.default)(startAt.fromLivePosition)) {
65
+ log_1.default.debug("Init: using startAt.fromLivePosition");
66
+ var livePosition = (_a = manifest.getLivePosition()) !== null && _a !== void 0 ? _a : max;
67
+ var fromLivePosition = startAt.fromLivePosition;
68
+ return fromLivePosition >= 0 ? livePosition :
69
+ Math.max(min, livePosition + fromLivePosition);
70
+ }
69
71
  else if (!(0, is_null_or_undefined_1.default)(startAt.percentage)) {
70
72
  log_1.default.debug("Init: using startAt.percentage");
71
73
  var percentage = startAt.percentage;
@@ -38,11 +38,6 @@ export type IInitialPlayEvent =
38
38
  export interface IInitialSeekAndPlayObject {
39
39
  /** Emit the result of the auto-play operation, once performed. */
40
40
  autoPlayResult: Promise<IInitialPlayEvent>;
41
- /**
42
- * Shared reference whose value becomes `true` once the initial seek has
43
- * been considered / has been done by `performInitialSeekAndPlay`.
44
- */
45
- initialSeekPerformed: IReadOnlySharedReference<boolean>;
46
41
  /**
47
42
  * Shared reference whose value becomes `true` once the initial play has
48
43
  * been considered / has been done by `performInitialSeekAndPlay`.
@@ -52,12 +47,15 @@ export interface IInitialSeekAndPlayObject {
52
47
  /**
53
48
  * Seek as soon as possible at the initially wanted position and play if
54
49
  * autoPlay is wanted.
55
- * @param {HTMLMediaElement} mediaElement
56
- * @param {Object} playbackObserver
57
- * @param {number|Function} startTime
58
- * @param {boolean} mustAutoPlay
59
- * @param {Function} onWarning
50
+ * @param {Object} args
60
51
  * @param {Object} cancelSignal
61
52
  * @returns {Object}
62
53
  */
63
- export default function performInitialSeekAndPlay(mediaElement: HTMLMediaElement, playbackObserver: PlaybackObserver, startTime: number | (() => number), mustAutoPlay: boolean, onWarning: (err: IPlayerError) => void, cancelSignal: CancellationSignal): IInitialSeekAndPlayObject;
54
+ export default function performInitialSeekAndPlay({ mediaElement, playbackObserver, startTime, mustAutoPlay, isDirectfile, onWarning }: {
55
+ mediaElement: HTMLMediaElement;
56
+ playbackObserver: PlaybackObserver;
57
+ startTime: number | (() => number);
58
+ mustAutoPlay: boolean;
59
+ isDirectfile: boolean;
60
+ onWarning: (err: IPlayerError) => void;
61
+ }, cancelSignal: CancellationSignal): IInitialSeekAndPlayObject;
@@ -16,116 +16,146 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  var compat_1 = require("../../../compat");
19
- var browser_compatibility_types_1 = require("../../../compat/browser_compatibility_types");
20
19
  var errors_1 = require("../../../errors");
21
20
  var log_1 = require("../../../log");
22
21
  var reference_1 = require("../../../utils/reference");
23
22
  /**
24
23
  * Seek as soon as possible at the initially wanted position and play if
25
24
  * autoPlay is wanted.
26
- * @param {HTMLMediaElement} mediaElement
27
- * @param {Object} playbackObserver
28
- * @param {number|Function} startTime
29
- * @param {boolean} mustAutoPlay
30
- * @param {Function} onWarning
25
+ * @param {Object} args
31
26
  * @param {Object} cancelSignal
32
27
  * @returns {Object}
33
28
  */
34
- function performInitialSeekAndPlay(mediaElement, playbackObserver, startTime, mustAutoPlay, onWarning, cancelSignal) {
35
- var resolveAutoPlay;
36
- var rejectAutoPlay;
37
- var autoPlayResult = new Promise(function (res, rej) {
38
- resolveAutoPlay = res;
39
- rejectAutoPlay = rej;
40
- });
41
- var initialSeekPerformed = new reference_1.default(false, cancelSignal);
29
+ function performInitialSeekAndPlay(_a, cancelSignal) {
30
+ var mediaElement = _a.mediaElement, playbackObserver = _a.playbackObserver, startTime = _a.startTime, mustAutoPlay = _a.mustAutoPlay, isDirectfile = _a.isDirectfile, onWarning = _a.onWarning;
42
31
  var initialPlayPerformed = new reference_1.default(false, cancelSignal);
43
- mediaElement.addEventListener("loadedmetadata", onLoadedMetadata);
44
- var deregisterCancellation = cancelSignal.register(function (err) {
45
- mediaElement.removeEventListener("loadedmetadata", onLoadedMetadata);
46
- rejectAutoPlay(err);
47
- });
48
- if (mediaElement.readyState >= browser_compatibility_types_1.READY_STATES.HAVE_METADATA) {
49
- onLoadedMetadata();
50
- }
51
- return { autoPlayResult: autoPlayResult, initialPlayPerformed: initialPlayPerformed, initialSeekPerformed: initialSeekPerformed };
52
- function onLoadedMetadata() {
53
- mediaElement.removeEventListener("loadedmetadata", onLoadedMetadata);
54
- var initialTime = typeof startTime === "function" ? startTime() :
55
- startTime;
56
- log_1.default.info("Init: Set initial time", initialTime);
57
- playbackObserver.setCurrentTime(initialTime);
58
- initialSeekPerformed.setValue(true);
59
- initialSeekPerformed.finish();
60
- if ((0, compat_1.shouldValidateMetadata)() && mediaElement.duration === 0) {
61
- var error = new errors_1.MediaError("MEDIA_ERR_NOT_LOADED_METADATA", "Cannot load automatically: your browser " +
62
- "falsely announced having loaded the content.");
63
- onWarning(error);
32
+ var autoPlayResult = new Promise(function (resolveAutoPlay, rejectAutoPlay) {
33
+ // `startTime` defined as a function might depend on metadata to make its
34
+ // choice, such as the content duration, minimum and/or maximum position.
35
+ //
36
+ // The RxPlayer might already know those through the Manifest file for
37
+ // non-Directfile contents, yet only through the `HTMLMediaElement` once a
38
+ // a sufficient `readyState` has been reached for directfile contents.
39
+ // So let's divide the two possibilities here.
40
+ if (!isDirectfile || typeof startTime === "number") {
41
+ playbackObserver.setCurrentTime(typeof startTime === "number" ? startTime : startTime());
42
+ waitForSeekable();
64
43
  }
65
- if (cancelSignal.isCancelled()) {
66
- return;
44
+ else {
45
+ playbackObserver.listen(function (obs, stopListening) {
46
+ if (obs.readyState >= 1) {
47
+ stopListening();
48
+ playbackObserver.setCurrentTime(typeof startTime === "number" ? startTime : startTime());
49
+ waitForSeekable();
50
+ }
51
+ }, { includeLastObservation: true, clearSignal: cancelSignal });
67
52
  }
68
- playbackObserver.listen(function (observation, stopListening) {
69
- if (!observation.seeking &&
70
- observation.rebuffering === null &&
71
- observation.readyState >= 1) {
53
+ var deregisterCancellation = cancelSignal.register(function (err) {
54
+ rejectAutoPlay(err);
55
+ });
56
+ /**
57
+ * Logic that should be run once the initial seek has been asked to the
58
+ * PlaybackObserver.
59
+ *
60
+ * Actually wait until the seek has been performed, wait for the right moment
61
+ * to perform autoplay, resolve the promise once everything has been done and
62
+ * potentially send warning if a minor issue is detected.
63
+ */
64
+ function waitForSeekable() {
65
+ playbackObserver.listen(function (obs, stopListening) {
66
+ if (obs.seeking === 0 /* SeekingState.None */ || obs.readyState === 0) {
67
+ return;
68
+ }
72
69
  stopListening();
73
- onPlayable();
74
- }
75
- }, { includeLastObservation: true, clearSignal: cancelSignal });
76
- }
77
- function onPlayable() {
78
- var _a;
79
- log_1.default.info("Init: Can begin to play content");
80
- if (!mustAutoPlay) {
81
- if (mediaElement.autoplay) {
82
- log_1.default.warn("Init: autoplay is enabled on HTML media element. " +
83
- "Media will play as soon as possible.");
84
- }
85
- initialPlayPerformed.setValue(true);
86
- initialPlayPerformed.finish();
87
- deregisterCancellation();
88
- return resolveAutoPlay({ type: "skipped" });
89
- }
90
- var playResult;
91
- try {
92
- playResult = (_a = mediaElement.play()) !== null && _a !== void 0 ? _a : Promise.resolve();
70
+ if ((0, compat_1.shouldValidateMetadata)() && mediaElement.duration === 0) {
71
+ var error = new errors_1.MediaError("MEDIA_ERR_NOT_LOADED_METADATA", "Cannot load automatically: your browser " +
72
+ "falsely announced having loaded the content.");
73
+ onWarning(error);
74
+ }
75
+ if (cancelSignal.isCancelled()) {
76
+ return;
77
+ }
78
+ waitForPlayable();
79
+ }, { includeLastObservation: true, clearSignal: cancelSignal });
93
80
  }
94
- catch (playError) {
95
- deregisterCancellation();
96
- return rejectAutoPlay(playError);
81
+ /**
82
+ * Logic that should be run once the initial seek has been properly performed.
83
+ *
84
+ * Wait for the media being playable before performing the autoplay operation
85
+ * if asked. Potentially send warning if a minor issue has been detected while
86
+ * doing so.
87
+ */
88
+ function waitForPlayable() {
89
+ playbackObserver.listen(function (observation, stopListening) {
90
+ if (observation.seeking === 0 /* SeekingState.None */ &&
91
+ observation.rebuffering === null &&
92
+ observation.readyState >= 1) {
93
+ stopListening();
94
+ onPlayable();
95
+ }
96
+ }, { includeLastObservation: true, clearSignal: cancelSignal });
97
97
  }
98
- playResult
99
- .then(function () {
100
- if (cancelSignal.isCancelled()) {
101
- return;
98
+ /**
99
+ * Callback called once the content is considered "playable".
100
+ *
101
+ * Perform the autoplay if needed, handling potential issues and resolve the
102
+ * Promise when done.
103
+ * Might also send warnings if minor issues arise.
104
+ */
105
+ function onPlayable() {
106
+ var _a;
107
+ log_1.default.info("Init: Can begin to play content");
108
+ if (!mustAutoPlay) {
109
+ if (mediaElement.autoplay) {
110
+ log_1.default.warn("Init: autoplay is enabled on HTML media element. " +
111
+ "Media will play as soon as possible.");
112
+ }
113
+ initialPlayPerformed.setValue(true);
114
+ initialPlayPerformed.finish();
115
+ deregisterCancellation();
116
+ return resolveAutoPlay({ type: "skipped" });
102
117
  }
103
- initialPlayPerformed.setValue(true);
104
- initialPlayPerformed.finish();
105
- deregisterCancellation();
106
- return resolveAutoPlay({ type: "autoplay" });
107
- })
108
- .catch(function (playError) {
109
- deregisterCancellation();
110
- if (cancelSignal.isCancelled()) {
111
- return;
118
+ var playResult;
119
+ try {
120
+ playResult = (_a = mediaElement.play()) !== null && _a !== void 0 ? _a : Promise.resolve();
112
121
  }
113
- if (playError instanceof Error && playError.name === "NotAllowedError") {
114
- // auto-play was probably prevented.
115
- log_1.default.warn("Init: Media element can't play." +
116
- " It may be due to browser auto-play policies.");
117
- var error = new errors_1.MediaError("MEDIA_ERR_BLOCKED_AUTOPLAY", "Cannot trigger auto-play automatically: " +
118
- "your browser does not allow it.");
119
- onWarning(error);
122
+ catch (playError) {
123
+ deregisterCancellation();
124
+ return rejectAutoPlay(playError);
125
+ }
126
+ playResult
127
+ .then(function () {
120
128
  if (cancelSignal.isCancelled()) {
121
129
  return;
122
130
  }
123
- return resolveAutoPlay({ type: "autoplay-blocked" });
124
- }
125
- else {
126
- rejectAutoPlay(playError);
127
- }
128
- });
129
- }
131
+ initialPlayPerformed.setValue(true);
132
+ initialPlayPerformed.finish();
133
+ deregisterCancellation();
134
+ return resolveAutoPlay({ type: "autoplay" });
135
+ })
136
+ .catch(function (playError) {
137
+ deregisterCancellation();
138
+ if (cancelSignal.isCancelled()) {
139
+ return;
140
+ }
141
+ if (playError instanceof Error && playError.name === "NotAllowedError") {
142
+ // auto-play was probably prevented.
143
+ log_1.default.warn("Init: Media element can't play." +
144
+ " It may be due to browser auto-play policies.");
145
+ var error = new errors_1.MediaError("MEDIA_ERR_BLOCKED_AUTOPLAY", "Cannot trigger auto-play automatically: " +
146
+ "your browser does not allow it.");
147
+ onWarning(error);
148
+ if (cancelSignal.isCancelled()) {
149
+ return;
150
+ }
151
+ return resolveAutoPlay({ type: "autoplay-blocked" });
152
+ }
153
+ else {
154
+ rejectAutoPlay(playError);
155
+ }
156
+ });
157
+ }
158
+ });
159
+ return { autoPlayResult: autoPlayResult, initialPlayPerformed: initialPlayPerformed };
130
160
  }
131
161
  exports.default = performInitialSeekAndPlay;