phaser/src/device/Video.js

82 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2020-01-15 12:07:09 +00:00
* @copyright 2020 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-02-12 16:01:20 +00:00
*/
/**
* Determines the video support of the browser running this Phaser Game instance.
* These values are read-only and populated during the boot sequence of the game.
* They are then referenced by internal game systems and are available for you to access
* via `this.sys.game.device.video` from within any Scene.
*
2019-10-04 10:13:11 +00:00
* In Phaser 3.20 the properties were renamed to drop the 'Video' suffix.
*
2018-03-28 14:04:09 +00:00
* @typedef {object} Phaser.Device.Video
* @since 3.0.0
2018-03-28 14:04:09 +00:00
*
* @property {boolean} h264 - Can this device play h264 mp4 video files?
* @property {boolean} hls - Can this device play hls video files?
* @property {boolean} mp4 - Can this device play h264 mp4 video files?
* @property {boolean} ogg - Can this device play ogg video files?
* @property {boolean} vp9 - Can this device play vp9 video files?
* @property {boolean} webm - Can this device play webm video files?
*/
2016-11-25 04:33:48 +00:00
var Video = {
h264: false,
hls: false,
mp4: false,
ogg: false,
vp9: false,
webm: false
2016-11-25 04:33:48 +00:00
};
function init ()
2016-11-25 04:33:48 +00:00
{
var videoElement = document.createElement('video');
var result = !!videoElement.canPlayType;
try
{
if (result)
{
if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, ''))
{
Video.ogg = true;
2016-11-25 04:33:48 +00:00
}
if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, ''))
{
// Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546
Video.h264 = true;
Video.mp4 = true;
2016-11-25 04:33:48 +00:00
}
if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, ''))
{
Video.webm = true;
2016-11-25 04:33:48 +00:00
}
if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, ''))
{
Video.vp9 = true;
2016-11-25 04:33:48 +00:00
}
if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, ''))
{
Video.hls = true;
2016-11-25 04:33:48 +00:00
}
}
}
catch (e)
{
// Nothing to do
}
return Video;
}
module.exports = init();