99abd78b by David LaPalomento

Reset the media index to zero when the video is ended and play is called

Before the invoking the Flash tech's play(), check if the video has ended. If it has, reset the media index so that the video replays.
1 parent 29d0951b
......@@ -604,6 +604,18 @@ videojs.Hls = videojs.Flash.extend({
this.bytesReceived = 0;
videojs.Hls.prototype.src.call(this, options.source && options.source.src);
},
/**
* Reset the mediaIndex if play() is called after the video has
* ended.
*/
play: function() {
if (this.ended()) {
this.mediaIndex = 0;
}
// delegate back to the Flash implementation
return videojs.Flash.prototype.play.apply(this, arguments);
}
});
......
......@@ -51,6 +51,7 @@ var
tech.vjs_getProperty = function() {};
tech.vjs_setProperty = function() {};
tech.vjs_src = function() {};
tech.vjs_play = function() {};
videojs.Flash.onReady(tech.id);
return player;
......@@ -1244,4 +1245,25 @@ test('calls ended() on the media source at the end of a playlist', function() {
strictEqual(endOfStreams, 1, 'ended media source');
});
test('calling play() at the end of a video resets the media index', function() {
player.src({
src: 'http://example.com/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
requests.shift().respond(200, null,
'#EXTM3U\n' +
'#EXTINF:10,\n' +
'0.ts\n' +
'#EXT-X-ENDLIST\n');
standardXHRResponse(requests.shift());
strictEqual(player.hls.mediaIndex, 1, 'index is 1 after the first segment');
player.hls.ended = function() {
return true;
};
player.play();
strictEqual(player.hls.mediaIndex, 0, 'index is 1 after the first segment');
});
})(window, window.videojs);
......