Last active
November 15, 2017 09:08
-
-
Save lotterfriends/5c3382e6edef7aecb0bf4021f1d525e2 to your computer and use it in GitHub Desktop.
create videojs Tech inline with vanilla js, integrate flv.js and video.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <video controls preload="auto" class="video-js myPlayer"> | |
// <source src="bla.flv" type='video/x-flv'> | |
// </video> | |
var Tech = videojs.getTech('Html5'); | |
FlashTech.prototype = Object.create(Tech.prototype); | |
function FlashTech(options) { | |
Tech.call(this, options); | |
this.techName = 'flash'; | |
this.setSrc = function(src) { | |
if (this.flvPlayer) { | |
this.flvPlayer.detachMediaElement(); | |
this.flvPlayer.destroy(); | |
} | |
this.flvPlayer = flvjs.createPlayer({ | |
type: 'flv', | |
url: src, | |
cors: true | |
}); | |
this.flvPlayer.attachMediaElement(this.el_); | |
this.flvPlayer.load(); | |
} | |
this.dispose = function() { | |
this.flvPlayer.detachMediaElement(); | |
this.flvPlayer.destroy(); | |
Tech.dispose.call(this); | |
} | |
}; | |
FlashTech.canPlaySource = function(srcObj, options) { | |
return FlashTech.canPlayType(srcObj.type); | |
}; | |
FlashTech.formats = { | |
'video/flv': 'FLV', | |
'video/x-flv': 'FLV' | |
}; | |
FlashTech.canPlayType = function(type) { | |
if (this.isSupported() && type in FlashTech.formats) { | |
return 'maybe'; | |
} | |
return ''; | |
}; | |
FlashTech.isSupported = function() { | |
return flvjs && flvjs.isSupported(); | |
}; | |
videojs.registerTech('flash', FlashTech); | |
var player = videojs('.myPlayer', { | |
techOrder: ['Html5', 'flash'] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment