This commit is contained in:
calzoneman 2015-07-03 11:24:21 -07:00
parent 9db9856a4e
commit 35500822d2
3 changed files with 67 additions and 34 deletions

View file

@ -1,10 +1,12 @@
guessMimeTypeBecauseBrowsersAreDumb = (link) ->
m = /.*\.([a-zA-Z0-9]+)[^.]*$/.exec(link)
if m
return m[1]
else
# Couldn't guess mime type; give up and hope flash can play it
return 'flv'
codecToMimeType = (codec) ->
switch codec
when 'mov/h264' then 'video/mp4'
when 'flv/h264' then 'video/flv'
when 'matroska/vp8', 'matroska/vp9' then 'video/webm'
when 'ogg/theora' then 'video/ogg'
when 'mp3' then 'audio/mp3'
when 'vorbis' then 'audio/vorbis'
else 'video/flv'
window.FilePlayer = class FilePlayer extends VideoJSPlayer
constructor: (data) ->
@ -13,7 +15,7 @@ window.FilePlayer = class FilePlayer extends VideoJSPlayer
data.meta.direct =
480: [{
contentType: guessMimeTypeBecauseBrowsersAreDumb(data.id)
contentType: codecToMimeType(data.meta.codec)
link: data.id
}]
super(data)
@ -21,7 +23,7 @@ window.FilePlayer = class FilePlayer extends VideoJSPlayer
load: (data) ->
data.meta.direct =
480: [{
contentType: guessMimeTypeBecauseBrowsersAreDumb(data.id)
contentType: codecToMimeType(data.meta.codec)
link: data.id
}]
super(data)

View file

@ -1,3 +1,11 @@
fixContentType = (contentType) ->
# TODO: In mediaquery, fix Google Drive/Google+ to return video/mp4,
# video/webm so this is unnecessary
if /^(video|audio)\//.test(contentType)
return contentType
else
return "video/#{contentType}"
sortSources = (sources) ->
if not sources
console.error('sortSources() called with null source list')
@ -17,8 +25,9 @@ sortSources = (sources) ->
flv = []
nonflv = []
sources[quality].forEach((source) ->
source.contentType = fixContentType(source.contentType)
source.quality = quality
if source.contentType == 'flv'
if source.contentType == 'video/flv'
flv.push(source)
else
nonflv.push(source)
@ -27,7 +36,7 @@ sortSources = (sources) ->
flvOrder = flvOrder.concat(flv)
return sourceOrder.concat(flvOrder).map((source) ->
type: "video/#{source.contentType}"
type: source.contentType
src: source.link
quality: source.quality
)
@ -42,7 +51,9 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
return new VideoJSPlayer(data)
@setMediaProperties(data)
@loadPlayer(data)
loadPlayer: (data) ->
waitUntilDefined(window, 'videojs', =>
video = $('<video/>')
.addClass('video-js vjs-default-skin embed-responsive-item')
@ -93,10 +104,11 @@ window.VideoJSPlayer = class VideoJSPlayer extends Player
load: (data) ->
@setMediaProperties(data)
if @player
@player.src(sortSources(data.meta.direct))
else
console.log('VideoJSPlayer::load() called but @player is undefined')
# Note: VideoJS does have facilities for loading new videos into the
# existing player object, however it appears to be pretty glitchy when
# a video can't be played (either previous or next video). It's safer
# to just reset the entire thing.
@loadPlayer(data)
play: ->
@paused = false