Skip to content

Commit

Permalink
@imbcmdth updated currentSrc to return src instead of blob urls in ht…
Browse files Browse the repository at this point in the history
…ml5 tech. Fixes #2232. closes #2232
  • Loading branch information
jrivera authored and gkatsev committed Jun 10, 2015
1 parent 86a11a0 commit 20b46b9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CHANGELOG
=========

## HEAD (Unreleased)
_(none)_
* @imbcmdth updated currentSrc to return src instead of blob urls in html5 tech. Fixes #2232 ([view](https://github.com/videojs/video.js/pull/2232))

--------------------

Expand Down
8 changes: 7 additions & 1 deletion src/js/media/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,13 @@ vjs.Html5.prototype.setSrc = function(src) {
};

vjs.Html5.prototype.load = function(){ this.el_.load(); };
vjs.Html5.prototype.currentSrc = function(){ return this.el_.currentSrc; };
vjs.Html5.prototype.currentSrc = function(){
if (this.currentSource_) {
return this.currentSource_.src;
} else {
return this.el_.currentSrc;
}
};

vjs.Html5.prototype.poster = function(){ return this.el_.poster; };
vjs.Html5.prototype.setPoster = function(val){ this.el_.poster = val; };
Expand Down
9 changes: 8 additions & 1 deletion src/js/media/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,14 @@ vjs.MediaTechController.withSourceHandlers = function(Tech){
this.disposeSourceHandler();
this.off('dispose', this.disposeSourceHandler);

this.currentSource_ = source;
// Set currentSource_ asynchronously to simulate the media element's
// asynchronous execution of the `resource selection algorithm`
this.setTimeout(vjs.bind(this, function () {
if (source && source.src !== '') {
this.currentSource_ = source;
}
}), 0);

this.sourceHandler_ = sh.handleSource(source, this);
this.on('dispose', this.disposeSourceHandler);

Expand Down
56 changes: 55 additions & 1 deletion test/unit/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ test('should add the source hanlder interface to a tech', function(){

// Pass a source through the source handler process of a tech instance
tech.setSource(sourceA);

// Increment clock since currentSource_ is set asynchronously
this.clock.tick(1);

strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored');
ok(tech.sourceHandler_.dispose, 'the handlerOne state instance was stored');

Expand Down Expand Up @@ -250,4 +254,54 @@ test('should handle unsupported sources with the source hanlder API', function()

tech.setSource('');
ok(usedNative, 'native source handler was used when an unsupported source was set');
});
});

test('should emulate the video element\'s behavior for currentSrc when src is set', function(){
var mockPlayer = {
off: this.noop,
trigger: this.noop
};
var sourceA = { src: 'foo.mp4', type: 'video/mp4' };
var sourceB = { src: '', type: 'video/mp4' };

// Define a new tech class
var Tech = videojs.MediaTechController.extend();

// Extend Tech with source handlers
vjs.MediaTechController.withSourceHandlers(Tech);

// Create an instance of Tech
var tech = new Tech(mockPlayer);

// Create source handlers
var handler = {
canHandleSource: function(source){
return 'probably';
},
handleSource: function(s, t){return {};}
};

Tech.registerSourceHandler(handler);

// Pass a source through the source handler process of a tech instance
tech.setSource(sourceA);

// Test that currentSource_ is not immediately specified
strictEqual(tech.currentSource_, undefined, 'sourceA was not stored immediately');

this.clock.tick(1);

// Test that currentSource_ is specified after yielding to the event loop
strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored');

// Pass a source with an empty src
tech.setSource(sourceB);

// Test that currentSource_ is not immediately changed
strictEqual(tech.currentSource_, sourceA, 'sourceB was not stored immediately');

this.clock.tick(1);

// Test that currentSource_ is still unchanged
strictEqual(tech.currentSource_, sourceA, 'sourceB was not stored if equal to the empty string');
});

0 comments on commit 20b46b9

Please sign in to comment.