Skip to content

Commit d178d9a

Browse files
authored
fix: Conditional requestVideoFrameCallback on Safari (#7854)
Safari's requestVideoFrameCallback is (intentionally?) broken when DRM is playing, so in that case use the fallback with requestAnimationFrame instead.
1 parent ebe9f32 commit d178d9a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/js/tech/html5.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,15 @@ class Html5 extends Tech {
745745

746746
/**
747747
* Native requestVideoFrameCallback if supported by browser/tech, or fallback
748+
* Don't use rVCF on Safari when DRM is playing, as it doesn't fire
749+
* Needs to be checked later than the constructor
750+
* This will be a false positive for clear sources loaded after a Fairplay source
748751
*
749752
* @param {function} cb function to call
750753
* @return {number} id of request
751754
*/
752755
requestVideoFrameCallback(cb) {
753-
if (this.featuresVideoFrameCallback) {
756+
if (this.featuresVideoFrameCallback && !this.el_.webkitKeys) {
754757
return this.el_.requestVideoFrameCallback(cb);
755758
}
756759
return super.requestVideoFrameCallback(cb);
@@ -762,7 +765,7 @@ class Html5 extends Tech {
762765
* @param {number} id request id to cancel
763766
*/
764767
cancelVideoFrameCallback(id) {
765-
if (this.featuresVideoFrameCallback) {
768+
if (this.featuresVideoFrameCallback && !this.el_.webkitKeys) {
766769
this.el_.cancelVideoFrameCallback(id);
767770
} else {
768771
super.cancelVideoFrameCallback(id);

test/unit/tech/html5.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -1044,3 +1044,20 @@ QUnit.test('featuresVideoFrameCallback is false for audio elements', function(as
10441044

10451045
audioTech.dispose();
10461046
});
1047+
1048+
QUnit.test('featuresVideoFrameCallback is false for Safari DRM', function(assert) {
1049+
// Looking for `super.requestVideoFrameCallback()` being called
1050+
const spy = sinon.spy(Object.getPrototypeOf(Object.getPrototypeOf(tech)), 'requestVideoFrameCallback');
1051+
1052+
tech.featuresVideoFrameCallback = true;
1053+
1054+
try {
1055+
tech.el_.webkitKeys = {};
1056+
tech.requestVideoFrameCallback(function() {});
1057+
1058+
assert.ok(spy.calledOnce, false, 'rvf fallback used');
1059+
} catch (e) {
1060+
// video.webkitKeys isn't writable on Safari, so relying on the mocked property on other browsers
1061+
assert.ok(true, 'skipped because webkitKeys not writable');
1062+
}
1063+
});

0 commit comments

Comments
 (0)