Add video.js source link fallback
This commit is contained in:
parent
050dec4d0f
commit
6ebd4af490
2 changed files with 32 additions and 7 deletions
|
|
@ -53,14 +53,15 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
|
|||
.attr(width: '100%', height: '100%')
|
||||
removeOld(video)
|
||||
|
||||
sources = sortSources(data.meta.direct)
|
||||
if sources.length == 0
|
||||
@sources = sortSources(data.meta.direct)
|
||||
if @sources.length == 0
|
||||
console.error('VideoJSPlayer::constructor(): data.meta.direct
|
||||
has no sources!')
|
||||
@mediaType = null
|
||||
return
|
||||
|
||||
sources.forEach((source) ->
|
||||
@sourceIdx = 0
|
||||
@sources.forEach((source) ->
|
||||
$('<source/>').attr(
|
||||
src: source.src
|
||||
type: source.type
|
||||
|
|
@ -84,6 +85,16 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
|
|||
|
||||
@player = videojs(video[0], autoplay: true, controls: true)
|
||||
@player.ready(=>
|
||||
@player.on('error', =>
|
||||
err = @player.error()
|
||||
if err and err.code == 4
|
||||
console.error('Caught error, trying next source')
|
||||
@sourceIdx++
|
||||
if @sourceIdx < @sources.length
|
||||
@player.src(@sources[@sourceIdx])
|
||||
else
|
||||
console.error('Out of sources, video will not play')
|
||||
)
|
||||
@setVolume(VOLUME)
|
||||
@player.on('ended', ->
|
||||
if CLIENT.leader
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue