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({ ...@@ -604,6 +604,18 @@ videojs.Hls = videojs.Flash.extend({
604 this.bytesReceived = 0; 604 this.bytesReceived = 0;
605 605
606 videojs.Hls.prototype.src.call(this, options.source && options.source.src); 606 videojs.Hls.prototype.src.call(this, options.source && options.source.src);
607 },
608 /**
609 * Reset the mediaIndex if play() is called after the video has
610 * ended.
611 */
612 play: function() {
613 if (this.ended()) {
614 this.mediaIndex = 0;
615 }
616
617 // delegate back to the Flash implementation
618 return videojs.Flash.prototype.play.apply(this, arguments);
607 } 619 }
608 }); 620 });
609 621
......
...@@ -51,6 +51,7 @@ var ...@@ -51,6 +51,7 @@ var
51 tech.vjs_getProperty = function() {}; 51 tech.vjs_getProperty = function() {};
52 tech.vjs_setProperty = function() {}; 52 tech.vjs_setProperty = function() {};
53 tech.vjs_src = function() {}; 53 tech.vjs_src = function() {};
54 tech.vjs_play = function() {};
54 videojs.Flash.onReady(tech.id); 55 videojs.Flash.onReady(tech.id);
55 56
56 return player; 57 return player;
...@@ -1244,4 +1245,25 @@ test('calls ended() on the media source at the end of a playlist', function() { ...@@ -1244,4 +1245,25 @@ test('calls ended() on the media source at the end of a playlist', function() {
1244 strictEqual(endOfStreams, 1, 'ended media source'); 1245 strictEqual(endOfStreams, 1, 'ended media source');
1245 }); 1246 });
1246 1247
1248 test('calling play() at the end of a video resets the media index', function() {
1249 player.src({
1250 src: 'http://example.com/media.m3u8',
1251 type: 'application/vnd.apple.mpegurl'
1252 });
1253 openMediaSource(player);
1254 requests.shift().respond(200, null,
1255 '#EXTM3U\n' +
1256 '#EXTINF:10,\n' +
1257 '0.ts\n' +
1258 '#EXT-X-ENDLIST\n');
1259 standardXHRResponse(requests.shift());
1260
1261 strictEqual(player.hls.mediaIndex, 1, 'index is 1 after the first segment');
1262 player.hls.ended = function() {
1263 return true;
1264 };
1265 player.play();
1266 strictEqual(player.hls.mediaIndex, 0, 'index is 1 after the first segment');
1267 });
1268
1247 })(window, window.videojs); 1269 })(window, window.videojs);
......