Add experimental support for dash streaming

This commit is contained in:
Calvin Montgomery 2017-11-27 22:10:00 -08:00
parent 67fbc8e267
commit cf9b95a265
6 changed files with 689 additions and 29 deletions

View file

@ -32,14 +32,15 @@ sortSources = (sources) ->
return sourceOrder.concat(flvOrder).map((source) ->
type: source.contentType
src: source.link
quality: source.quality
res: source.quality
label: getSourceLabel(source)
)
getSourceLabel = (source) ->
if source.quality is 'auto'
if source.res is 'auto'
return 'auto'
else
return "#{source.quality}p #{source.type.split('/')[1]}"
return "#{source.quality}p #{source.contentType.split('/')[1]}"
waitUntilDefined(window, 'videojs', =>
videojs.options.flash.swf = '/video-js.swf'
@ -74,14 +75,6 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
return
@sourceIdx = 0
@sources.forEach((source) ->
$('<source/>').attr(
src: source.src
type: source.type
res: source.quality
label: getSourceLabel(source)
).appendTo(video)
)
# TODO: Refactor VideoJSPlayer to use a preLoad()/load()/postLoad() pattern
# VideoJSPlayer should provide the core functionality and logic for specific
@ -112,17 +105,22 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
)
@player = videojs(video[0],
autoplay: true,
# https://github.com/Dash-Industry-Forum/dash.js/issues/2184
autoplay: @sources[0].type != 'application/dash+xml',
controls: true,
plugins:
videoJsResolutionSwitcher:
default: @sources[0].quality
default: @sources[0].res
)
@player.ready(=>
# Have to use updateSrc instead of <source> tags
# see: https://github.com/videojs/video.js/issues/3428
@player.updateSrc(@sources)
@player.on('error', =>
err = @player.error()
if err and err.code == 4
console.error('Caught error, trying next source')
# Does this really need to be done manually?
@sourceIdx++
if @sourceIdx < @sources.length
@player.src(@sources[@sourceIdx])