-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polyfill video.play to silence confusing errors
Closes #836 Change-Id: Ie5b42bc707ce7443641e86c04ec116fd732bbbae
- Loading branch information
1 parent
a93b023
commit d901460
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @license | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
goog.provide('shaka.polyfill.VideoPlayPromise'); | ||
|
||
goog.require('shaka.log'); | ||
goog.require('shaka.polyfill.register'); | ||
|
||
|
||
/** | ||
* @namespace shaka.polyfill.VideoPlayPromise | ||
* | ||
* @summary A polyfill to silence the play() Promise in HTML5 video. | ||
*/ | ||
|
||
|
||
/** | ||
* Install the polyfill if needed. | ||
*/ | ||
shaka.polyfill.VideoPlayPromise.install = function() { | ||
shaka.log.debug('VideoPlayPromise.install'); | ||
|
||
if (window.HTMLMediaElement) { | ||
var originalPlay = HTMLMediaElement.prototype.play; | ||
HTMLMediaElement.prototype.play = function() { | ||
var p = originalPlay.apply(this, arguments); | ||
if (p) { | ||
// This browser is returning a Promise from play(). | ||
// If the play() call fails or is interrupted, the Promise will be | ||
// rejected. Some apps, however, don't listen to this Promise, | ||
// especially since it is not available cross-browser. If the Promise | ||
// is rejected without anyone listening for the failure, an error will | ||
// appear in the JS console. | ||
// To avoid confusion over this innocuous "error", we will install a | ||
// catch handler on the Promise. This does not prevent the app from | ||
// also catching failures and handling them. It only prevents the | ||
// console message. | ||
p.catch(function() {}); | ||
} | ||
return p; | ||
}; | ||
} | ||
}; | ||
|
||
shaka.polyfill.register(shaka.polyfill.VideoPlayPromise.install); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters