Ensure Flash mode fires "loadstart"
For #400. Flash doesn't currently fire "loadstart" in data generation mode. Triggering that event should probably happen in video.js itself but fire it once the source handler is selected to make things behave somewhat sanely for now.
Showing
2 changed files
with
39 additions
and
6 deletions
... | @@ -102,6 +102,13 @@ videojs.HlsSourceHandler = function(mode) { | ... | @@ -102,6 +102,13 @@ videojs.HlsSourceHandler = function(mode) { |
102 | return mpegurlRE.test(srcObj.type); | 102 | return mpegurlRE.test(srcObj.type); |
103 | }, | 103 | }, |
104 | handleSource: function(source, tech) { | 104 | handleSource: function(source, tech) { |
105 | if (mode === 'flash') { | ||
106 | // We need to trigger this asynchronously to give others the chance | ||
107 | // to bind to the event when a source is set at player creation | ||
108 | tech.setTimeout(function() { | ||
109 | tech.trigger('loadstart'); | ||
110 | }, 1); | ||
111 | } | ||
105 | tech.hls = new videojs.Hls(tech, { | 112 | tech.hls = new videojs.Hls(tech, { |
106 | source: source, | 113 | source: source, |
107 | mode: mode | 114 | mode: mode |
... | @@ -139,12 +146,6 @@ videojs.Hls.prototype.src = function(src) { | ... | @@ -139,12 +146,6 @@ videojs.Hls.prototype.src = function(src) { |
139 | // load the MediaSource into the player | 146 | // load the MediaSource into the player |
140 | this.mediaSource.addEventListener('sourceopen', this.handleSourceOpen.bind(this)); | 147 | this.mediaSource.addEventListener('sourceopen', this.handleSourceOpen.bind(this)); |
141 | 148 | ||
142 | // We need to trigger this asynchronously to give others the chance | ||
143 | // to bind to the event when a source is set at player creation | ||
144 | this.setTimeout(function() { | ||
145 | this.tech_.trigger('loadstart'); | ||
146 | }.bind(this), 1); | ||
147 | |||
148 | // The index of the next segment to be downloaded in the current | 149 | // The index of the next segment to be downloaded in the current |
149 | // media playlist. When the current media playlist is live with | 150 | // media playlist. When the current media playlist is live with |
150 | // expiring segments, it may be a different value from the media | 151 | // expiring segments, it may be a different value from the media | ... | ... |
... | @@ -2594,6 +2594,38 @@ test('the source handler supports HLS mime types', function() { | ... | @@ -2594,6 +2594,38 @@ test('the source handler supports HLS mime types', function() { |
2594 | }); | 2594 | }); |
2595 | }); | 2595 | }); |
2596 | 2596 | ||
2597 | test('fires loadstart manually if Flash is used', function() { | ||
2598 | var | ||
2599 | tech = new (videojs.extend(videojs.EventTarget, { | ||
2600 | buffered: function() { | ||
2601 | return videojs.createTimeRange(); | ||
2602 | }, | ||
2603 | currentTime: function() { | ||
2604 | return 0; | ||
2605 | }, | ||
2606 | el: function() { | ||
2607 | return {}; | ||
2608 | }, | ||
2609 | preload: function() { | ||
2610 | return 'auto'; | ||
2611 | }, | ||
2612 | src: function() {}, | ||
2613 | setTimeout: window.setTimeout | ||
2614 | }))(), | ||
2615 | loadstarts = 0; | ||
2616 | tech.on('loadstart', function() { | ||
2617 | loadstarts++; | ||
2618 | }); | ||
2619 | videojs.HlsSourceHandler('flash').handleSource({ | ||
2620 | src: 'movie.m3u8', | ||
2621 | type: 'application/x-mpegURL' | ||
2622 | }, tech); | ||
2623 | |||
2624 | equal(loadstarts, 0, 'loadstart is not synchronous'); | ||
2625 | clock.tick(1); | ||
2626 | equal(loadstarts, 1, 'fired loadstart'); | ||
2627 | }); | ||
2628 | |||
2597 | test('has no effect if native HLS is available', function() { | 2629 | test('has no effect if native HLS is available', function() { |
2598 | var player; | 2630 | var player; |
2599 | videojs.Hls.supportsNativeHls = true; | 2631 | videojs.Hls.supportsNativeHls = true; | ... | ... |
-
Please register or sign in to post a comment