diff --git a/src/js/exports.js b/src/js/exports.js index 560a0728b1..620e3a651f 100644 --- a/src/js/exports.js +++ b/src/js/exports.js @@ -157,6 +157,7 @@ goog.exportSymbol('videojs.Flash', vjs.Flash); goog.exportProperty(vjs.Flash, 'isSupported', vjs.Flash.isSupported); goog.exportProperty(vjs.Flash, 'canPlaySource', vjs.Flash.canPlaySource); goog.exportProperty(vjs.Flash, 'onReady', vjs.Flash['onReady']); +goog.exportProperty(vjs.Flash, 'embed', vjs.Flash.embed); goog.exportSymbol('videojs.TextTrack', vjs.TextTrack); goog.exportProperty(vjs.TextTrack.prototype, 'label', vjs.TextTrack.prototype.label); diff --git a/src/js/media/flash.js b/src/js/media/flash.js index f78a3ffd2a..445de46901 100644 --- a/src/js/media/flash.js +++ b/src/js/media/flash.js @@ -331,8 +331,32 @@ vjs.Flash.version = function(){ return version.split(','); }; +// Compare Flash version. Returns -1 for lower version, 0 for same and 1 for bigger. +vjs.Flash.compareVersion = function(version){ + var myVer = vjs.Flash.version(), + requiredVer = String(version).split(','); + + for(var i = 0; i < 3; i++){ + var myVerNum = parseInt(myVer[i], 10), + requiredVerNum = parseInt(requiredVer[i] || 0, 10); + if(myVerNum == requiredVerNum){ + continue; + }else if(myVerNum > requiredVerNum){ + return 1; + }else{ + return -1; + } + } + + return 0; +}; + // Flash embedding method. Only used in non-iframe mode -vjs.Flash.embed = function(swf, placeHolder, flashVars, params, attributes){ +vjs.Flash.embed = function(swf, placeHolder, flashVars, params, attributes, version){ + if(version && vjs.Flash.checkVersion(version) == -1){ + throw new Error('The latest Flash Player is not installed on your machine. Please go here to install it and try again.'); + } + var code = vjs.Flash.getEmbedCode(swf, flashVars, params, attributes), // Get element by embedding code and retrieving created element diff --git a/test/unit/flash.js b/test/unit/flash.js index 3471414587..75afd23b30 100644 --- a/test/unit/flash.js +++ b/test/unit/flash.js @@ -143,3 +143,11 @@ test('ready triggering before and after disposing the tech', function() { vjs.Flash['checkReady'].restore(); }); + +test('compareVersion compares versions properly', function(){ + var stub = sinon.stub(vjs.Flash, 'version').returns(['10', '1', '1']); + equal(vjs.Flash.compareVersion(11), -1); + equal(vjs.Flash.compareVersion(9), 1); + equal(vjs.Flash.compareVersion('10,1,1'), 0); + stub.restore(); +});