Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable HLS hack on Firefox for Android (with tests) #3586

Merged
merged 5 commits into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/tech/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ const mp4RE = /^video\/mp4/i;

Html5.patchCanPlayType = function() {
// Android 4.0 and above can play HLS to some extent but it reports being unable to do so
if (browser.ANDROID_VERSION >= 4.0) {
if (browser.ANDROID_VERSION >= 4.0 && !browser.IS_FIREFOX) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw an update to the firefox beta which said they're getting HLS support. Is this something that we should possibly account for? Maybe check if firefox version is less than 50?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The support in Firefox 50 is not polished, there are a lot of bugs (e.g. https://bugzilla.mozilla.org/show_bug.cgi?id=1301050). It will probably be disabled in 50.
We're using a hacky solution, so it will never be like a properly supported codec.
I would leave it as is and expect Firefox not to return wrong values in canPlayType, if it will ever support HLS natively, it will be returned in canPlayType.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could also always update this at a later time once/if it officially ships.

if (!canPlayType) {
canPlayType = Html5.TEST_VID.constructor.prototype.canPlayType;
}
Expand Down
28 changes: 28 additions & 0 deletions test/unit/tech/html5.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ QUnit.test('patchCanPlayType patches canplaytype with our function, conditionall
Html5.unpatchCanPlayType();

const oldAV = browser.ANDROID_VERSION;
const oldIsFirefox = browser.IS_FIREFOX;
const video = document.createElement('video');
const canPlayType = Html5.TEST_VID.constructor.prototype.canPlayType;

browser.ANDROID_VERSION = 4.0;
browser.IS_FIREFOX = false;
Html5.patchCanPlayType();

assert.notStrictEqual(video.canPlayType,
Expand All @@ -131,14 +133,39 @@ QUnit.test('patchCanPlayType patches canplaytype with our function, conditionall
'patched canPlayType and function returned from unpatch are equal');

browser.ANDROID_VERSION = oldAV;
browser.IS_FIREFOX = oldIsFirefox;
Html5.unpatchCanPlayType();
});

QUnit.test('patchCanPlayType doesn\'t patch canplaytype with our function in Firefox for Android', function(assert) {
// the patch runs automatically so we need to first unpatch
Html5.unpatchCanPlayType();

const oldAV = browser.ANDROID_VERSION;
const oldIsFirefox = browser.IS_FIREFOX;
const video = document.createElement('video');
const canPlayType = Html5.TEST_VID.constructor.prototype.canPlayType;

browser.ANDROID_VERSION = 4.0;
browser.IS_FIREFOX = true;
Html5.patchCanPlayType();

assert.strictEqual(video.canPlayType,
canPlayType,
'original canPlayType and patched canPlayType should be equal');

browser.ANDROID_VERSION = oldAV;
browser.IS_FIREFOX = oldIsFirefox;
Html5.unpatchCanPlayType();
});

QUnit.test('should return maybe for HLS urls on Android 4.0 or above', function(assert) {
const oldAV = browser.ANDROID_VERSION;
const oldIsFirefox = browser.IS_FIREFOX;
const video = document.createElement('video');

browser.ANDROID_VERSION = 4.0;
browser.IS_FIREFOX = false;
Html5.patchCanPlayType();

assert.strictEqual(video.canPlayType('application/x-mpegurl'),
Expand All @@ -157,6 +184,7 @@ QUnit.test('should return maybe for HLS urls on Android 4.0 or above', function(
'maybe for vnd.apple.mpegurl');

browser.ANDROID_VERSION = oldAV;
browser.IS_FIREFOX = oldIsFirefox;
Html5.unpatchCanPlayType();
});

Expand Down