Skip to content

Commit f3e9dab

Browse files
zanguejoeyparrish
authored andcommitted
fix: config.streaming.preferNativeHls only applies to HLS streams (#5167)
Closes #5166
1 parent 2203087 commit f3e9dab

File tree

6 files changed

+84
-1
lines changed

6 files changed

+84
-1
lines changed

lib/player.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
11481148
*/
11491149
shouldUseSrcEquals_(payload) {
11501150
const Platform = shaka.util.Platform;
1151+
const MimeUtils = shaka.util.MimeUtils;
11511152

11521153
// If we are using a platform that does not support media source, we will
11531154
// fall back to src= to handle all playback.
@@ -1202,7 +1203,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
12021203
// version there.
12031204

12041205
// Native HLS can be preferred on any platform via this flag:
1205-
if (this.config_.streaming.preferNativeHls) {
1206+
if (MimeUtils.isHlsType(mimeType) &&
1207+
this.config_.streaming.preferNativeHls) {
12061208
return true;
12071209
}
12081210

lib/util/mime_utils.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ shaka.util.MimeUtils = class {
194194
return value;
195195
}
196196

197+
/**
198+
* Checks if the given MIME type is HLS MIME type.
199+
*
200+
* @param {string} mimeType
201+
* @return {boolean}
202+
*/
203+
static isHlsType(mimeType) {
204+
return mimeType === 'application/x-mpegurl' ||
205+
mimeType === 'application/vnd.apple.mpegurl';
206+
}
207+
197208
/**
198209
* Get the base and profile of a codec string. Where [0] will be the codec
199210
* base and [1] will be the profile.

test/player_unit.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,60 @@ describe('Player', () => {
370370
expect(streamingEngine.unloadTextStream).not.toHaveBeenCalled();
371371
});
372372
});
373+
374+
describe('when config.streaming.preferNativeHls is set to true', () => {
375+
beforeEach(() => {
376+
shaka.media.ManifestParser.registerParserByMime(
377+
'application/x-mpegurl',
378+
() => new shaka.test.FakeManifestParser(manifest));
379+
});
380+
381+
afterEach(() => {
382+
shaka.media.ManifestParser.unregisterParserByMime(
383+
'application/x-mpegurl');
384+
video.canPlayType.calls.reset();
385+
});
386+
387+
it('only applies to HLS streams', async () => {
388+
video.canPlayType.and.returnValue('maybe');
389+
spyOn(shaka.util.Platform, 'anyMediaElement').and.returnValue(video);
390+
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
391+
spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);
392+
// Make sure player.load() resolves for src=
393+
spyOn(shaka.util.MediaReadyState, 'waitForReadyState').and.callFake(
394+
(mediaElement, readyState, eventManager, callback) => {
395+
callback();
396+
});
397+
398+
player.configure({
399+
streaming: {
400+
preferNativeHls: true,
401+
useNativeHlsOnSafari: false,
402+
},
403+
});
404+
405+
await player.load(fakeManifestUri, undefined, 'application/x-mpegurl');
406+
407+
expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.SRC_EQUALS);
408+
});
409+
410+
it('does not apply to non-HLS streams', async () => {
411+
video.canPlayType.and.returnValue('maybe');
412+
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
413+
spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);
414+
415+
player.configure({
416+
streaming: {
417+
preferNativeHls: true,
418+
useNativeHlsOnSafari: false,
419+
},
420+
});
421+
422+
await player.load(fakeManifestUri, 0, fakeMimeType);
423+
424+
expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.MEDIA_SOURCE);
425+
});
426+
});
373427
}); // describe('load/unload')
374428

375429
describe('getConfiguration', () => {

test/test/util/fake_drm_engine.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ shaka.test.FakeDrmEngine = class {
7474
/** @type {!jasmine.Spy} */
7575
this.supportsVariant = jasmine.createSpy('supportsVariant');
7676
this.supportsVariant.and.returnValue(true);
77+
78+
/** @type {!jasmine.Spy} */
79+
this.setSrcEquals = jasmine.createSpy('setSrcEquals');
7780
}
7881

7982
/**

test/test/util/simple_fakes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ shaka.test.FakeVideo = class {
225225

226226
/** @type {!jasmine.Spy} */
227227
this.dispatchEvent = jasmine.createSpy('dispatchEvent');
228+
229+
/** @type {!jasmine.Spy} */
230+
this.canPlayType = jasmine.createSpy('canPlayType');
228231
}
229232
};
230233

test/util/mime_utils_unit.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,14 @@ describe('MimeUtils', () => {
5151
expect(getNormalizedCodec('dvh1.05')).toBe('dovi');
5252
expect(getNormalizedCodec('dvhe.05')).toBe('dovi');
5353
});
54+
55+
it('isHlsType', () => {
56+
const isHlsType = (mimeType) => shaka.util.MimeUtils.isHlsType(mimeType);
57+
58+
expect(isHlsType('application/x-mpegurl')).toBe(true);
59+
expect(isHlsType('application/vnd.apple.mpegurl')).toBe(true);
60+
expect(isHlsType('application/dash+xml')).toBe(false);
61+
expect(isHlsType('application/vnd.ms-sstr+xml')).toBe(false);
62+
expect(isHlsType('foo')).toBe(false);
63+
});
5464
});

0 commit comments

Comments
 (0)