diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a6f300d3..521188f7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG * @vdeshpande fixed control text for fullscreen button ([view](https://github.com/videojs/video.js/pull/3485)) * @mister-ben fixed android treating swipe as a tap ([view](https://github.com/videojs/video.js/pull/3514)) * @mboles updated duration() method documentation ([view](https://github.com/videojs/video.js/pull/3515)) +* @mister-ben silenced chrome's play() request was interrupted by pause() error ([view](https://github.com/videojs/video.js/pull/3518)) -------------------- diff --git a/src/js/tech/html5.js b/src/js/tech/html5.js index 8d72e042c..b3bfc66f4 100644 --- a/src/js/tech/html5.js +++ b/src/js/tech/html5.js @@ -423,7 +423,15 @@ class Html5 extends Tech { * * @method play */ - play() { this.el_.play(); } + play() { + const playPromise = this.el_.play(); + + // Catch/silence error when a pause interrupts a play request + // on browsers which return a promise + if (playPromise !== undefined && typeof playPromise.then === 'function') { + playPromise.then(null, (e) => {}); + } + } /** * Pause for html5 tech diff --git a/test/unit/tech/html5.test.js b/test/unit/tech/html5.test.js index 92ac0fbc8..c1335ac3f 100644 --- a/test/unit/tech/html5.test.js +++ b/test/unit/tech/html5.test.js @@ -442,3 +442,20 @@ test('Html5#reset calls Html5.resetMediaElement when called', function() { Html5.resetMediaElement = oldResetMedia; }); + +QUnit.test('Exception in play promise should be caught', function() { + const oldEl = tech.el_; + + tech.el_ = { + play: () => { + return new Promise(function(resolve, reject) { + reject(new DOMException()); + }); + } + }; + + tech.play(); + QUnit.ok(true, 'error was caught'); + + tech.el_ = oldEl; +});