From 7184cb4b498a6ac97b96ac493c8a91191a70506a Mon Sep 17 00:00:00 2001 From: David LaPalomento Date: Sat, 25 Jan 2014 22:37:40 -0500 Subject: [PATCH 1/2] src() called as a getter should return the video src It can be handy that src() returns the player object when it is invoked but it does not match the behavior of the corresponding property on the video element. Ignoring the spec however, while the video element is running the resource selection algorithm, currentSrc may be undefined. If the video source has been specified through an attribute on the video element, src() is the natural way to expose that URL programmatically. Without this change, it's necessary to bypass the player and interact with the tech directly to determine the value of the src attribute. --- src/js/player.js | 8 ++++++-- test/unit/mediafaker.js | 1 + test/unit/player.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index 636e8797b..1f9f68c9b 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -1014,9 +1014,13 @@ vjs.Player.prototype.selectSource = function(sources){ * ]); * * @param {String|Object|Array=} source The source URL, object, or array of sources - * @return {vjs.Player} self + * @return {String} The current video source */ vjs.Player.prototype.src = function(source){ + if (source === undefined) { + return this.techGet('src'); + } + // Case: Array of source objects to choose from and pick the best to play if (source instanceof Array) { @@ -1069,7 +1073,7 @@ vjs.Player.prototype.src = function(source){ } } } - return this; + return source; }; // Begin loading the src data diff --git a/test/unit/mediafaker.js b/test/unit/mediafaker.js index a5a9e0804..124e5a555 100644 --- a/test/unit/mediafaker.js +++ b/test/unit/mediafaker.js @@ -36,6 +36,7 @@ vjs.MediaFaker.prototype['setPoster'] = function(val){ this.el().poster = val; } vjs.MediaFaker.prototype.currentTime = function(){ return 0; }; vjs.MediaFaker.prototype.seeking = function(){ return false; }; +vjs.MediaFaker.prototype.src = function(){ return 'movie.mp4'; }; vjs.MediaFaker.prototype.volume = function(){ return 0; }; vjs.MediaFaker.prototype.muted = function(){ return false; }; vjs.MediaFaker.prototype.pause = function(){ return false; }; diff --git a/test/unit/player.js b/test/unit/player.js index 4b8f135d5..0984d72e1 100644 --- a/test/unit/player.js +++ b/test/unit/player.js @@ -357,6 +357,16 @@ test('should use custom message when encountering an unsupported video type', player.dispose(); }); +test('should delegate to the tech for src accesses', function() { + var + player = PlayerTest.makePlayer({}), + src; + src = player.src(); + + notEqual(src, player, 'the player is not returned'); + equal('string', typeof src, 'a URL is returned'); +}); + test('should register players with generated ids', function(){ var fixture, video, player, id; fixture = document.getElementById('qunit-fixture'); From e9da3350d436e5344cc1365a154d2c4b942bc802 Mon Sep 17 00:00:00 2001 From: Steve Heffernan Date: Thu, 27 Feb 2014 17:34:01 -0800 Subject: [PATCH 2/2] Made the src method return the player when setting, and made Flash return the current srouce for flash.src() --- src/js/media/flash.js | 11 +++++++---- src/js/player.js | 6 ++++-- test/unit/player.js | 13 ++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/js/media/flash.js b/src/js/media/flash.js index 126bdb6fe..e0525bb75 100644 --- a/src/js/media/flash.js +++ b/src/js/media/flash.js @@ -243,12 +243,15 @@ vjs.Flash.prototype.pause = function(){ }; vjs.Flash.prototype.src = function(src){ + if (src === undefined) { + return this.currentSrc(); + } + if (vjs.Flash.isStreamingSrc(src)) { src = vjs.Flash.streamToParts(src); this.setRtmpConnection(src.connection); this.setRtmpStream(src.stream); - } - else { + } else { // Make sure source URL is abosolute. src = vjs.getAbsoluteURL(src); this.el_.vjs_src(src); @@ -303,8 +306,8 @@ vjs.Flash.prototype.enterFullScreen = function(){ // Create setters and getters for attributes var api = vjs.Flash.prototype, readWrite = 'rtmpConnection,rtmpStream,preload,currentTime,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(','), - readOnly = 'error,currentSrc,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks'.split(','); - // Overridden: buffered + readOnly = 'error,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks'.split(','); + // Overridden: buffered, currentSrc /** * @this {*} diff --git a/src/js/player.js b/src/js/player.js index 1f9f68c9b..bd5573f3f 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -1014,7 +1014,8 @@ vjs.Player.prototype.selectSource = function(sources){ * ]); * * @param {String|Object|Array=} source The source URL, object, or array of sources - * @return {String} The current video source + * @return {String} The current video source when getting + * @return {String} The player when setting */ vjs.Player.prototype.src = function(source){ if (source === undefined) { @@ -1073,7 +1074,8 @@ vjs.Player.prototype.src = function(source){ } } } - return source; + + return this; }; // Begin loading the src data diff --git a/test/unit/player.js b/test/unit/player.js index 0984d72e1..be3dc4dad 100644 --- a/test/unit/player.js +++ b/test/unit/player.js @@ -357,14 +357,13 @@ test('should use custom message when encountering an unsupported video type', player.dispose(); }); -test('should delegate to the tech for src accesses', function() { - var - player = PlayerTest.makePlayer({}), - src; - src = player.src(); +test('should return the player when setting src', function() { + var player, ret; - notEqual(src, player, 'the player is not returned'); - equal('string', typeof src, 'a URL is returned'); + player = PlayerTest.makePlayer({}), + ret = player.src('foo'); + + equal(player, ret, 'the player is returned'); }); test('should register players with generated ids', function(){