2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2023-01-02 17:36:27 +00:00
|
|
|
* @copyright 2013-2023 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
|
|
|
*/
|
|
|
|
|
2023-04-11 16:01:42 +00:00
|
|
|
var GetFastValue = require('../utils/object/GetFastValue');
|
|
|
|
|
2018-01-25 17:03:35 +00:00
|
|
|
/**
|
|
|
|
* Determines the video support of the browser running this Phaser Game instance.
|
2023-04-11 00:34:13 +00:00
|
|
|
*
|
2018-01-25 17:03:35 +00:00
|
|
|
* These values are read-only and populated during the boot sequence of the game.
|
2023-04-11 00:34:13 +00:00
|
|
|
*
|
2018-01-25 17:03:35 +00:00
|
|
|
* 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.
|
2021-01-19 09:40:59 +00:00
|
|
|
*
|
2019-10-04 10:13:11 +00:00
|
|
|
* In Phaser 3.20 the properties were renamed to drop the 'Video' suffix.
|
2021-01-19 09:40:59 +00:00
|
|
|
*
|
2018-03-28 14:04:09 +00:00
|
|
|
* @typedef {object} Phaser.Device.Video
|
2018-01-25 17:03:35 +00:00
|
|
|
* @since 3.0.0
|
2021-01-19 09:40:59 +00:00
|
|
|
*
|
2019-10-03 13:13:56 +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?
|
2021-11-01 17:33:44 +00:00
|
|
|
* @property {boolean} m4v - Can this device play m4v (typically mp4) video files?
|
2019-10-03 13:13:56 +00:00
|
|
|
* @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?
|
2023-04-11 16:01:42 +00:00
|
|
|
* @property {function} getVideoURL - Returns the first video URL that can be played by this browser.
|
2018-01-25 17:03:35 +00:00
|
|
|
*/
|
2016-11-25 04:33:48 +00:00
|
|
|
var Video = {
|
|
|
|
|
2019-10-03 13:13:56 +00:00
|
|
|
h264: false,
|
|
|
|
hls: false,
|
|
|
|
mp4: false,
|
2021-11-01 17:33:44 +00:00
|
|
|
m4v: false,
|
2019-10-03 13:13:56 +00:00
|
|
|
ogg: false,
|
|
|
|
vp9: false,
|
2023-04-11 00:34:13 +00:00
|
|
|
webm: false,
|
|
|
|
hasRequestVideoFrame: false
|
2016-11-25 04:33:48 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-26 01:28:53 +00:00
|
|
|
function init ()
|
2016-11-25 04:33:48 +00:00
|
|
|
{
|
2021-01-19 09:40:59 +00:00
|
|
|
if (typeof importScripts === 'function')
|
|
|
|
{
|
|
|
|
return Video;
|
|
|
|
}
|
|
|
|
|
2016-11-25 04:33:48 +00:00
|
|
|
var videoElement = document.createElement('video');
|
|
|
|
var result = !!videoElement.canPlayType;
|
2021-11-01 17:33:44 +00:00
|
|
|
var no = /^no$/;
|
2016-11-25 04:33:48 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
{
|
2021-11-01 17:33:44 +00:00
|
|
|
if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(no, ''))
|
2016-11-25 04:33:48 +00:00
|
|
|
{
|
2019-10-03 13:13:56 +00:00
|
|
|
Video.ogg = true;
|
2016-11-25 04:33:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 17:33:44 +00:00
|
|
|
if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(no, ''))
|
2016-11-25 04:33:48 +00:00
|
|
|
{
|
|
|
|
// Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546
|
2019-10-03 13:13:56 +00:00
|
|
|
Video.h264 = true;
|
|
|
|
Video.mp4 = true;
|
2016-11-25 04:33:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 17:33:44 +00:00
|
|
|
if (videoElement.canPlayType('video/x-m4v').replace(no, ''))
|
|
|
|
{
|
|
|
|
Video.m4v = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(no, ''))
|
2016-11-25 04:33:48 +00:00
|
|
|
{
|
2019-10-03 13:13:56 +00:00
|
|
|
Video.webm = true;
|
2016-11-25 04:33:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 17:33:44 +00:00
|
|
|
if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(no, ''))
|
2016-11-25 04:33:48 +00:00
|
|
|
{
|
2019-10-03 13:13:56 +00:00
|
|
|
Video.vp9 = true;
|
2016-11-25 04:33:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 17:33:44 +00:00
|
|
|
if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(no, ''))
|
2016-11-25 04:33:48 +00:00
|
|
|
{
|
2019-10-03 13:13:56 +00:00
|
|
|
Video.hls = true;
|
2016-11-25 04:33:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
2023-04-11 00:34:13 +00:00
|
|
|
if (videoElement.parentNode)
|
|
|
|
{
|
|
|
|
videoElement.parentNode.removeChild(videoElement);
|
|
|
|
}
|
|
|
|
|
2023-04-11 16:01:42 +00:00
|
|
|
Video.getVideoURL = function (urls)
|
|
|
|
{
|
|
|
|
if (!Array.isArray(urls))
|
|
|
|
{
|
|
|
|
urls = [ urls ];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < urls.length; i++)
|
|
|
|
{
|
|
|
|
var url = GetFastValue(urls[i], 'url', urls[i]);
|
|
|
|
|
|
|
|
if (url.indexOf('blob:') === 0)
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
url: url,
|
|
|
|
type: ''
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var videoType;
|
|
|
|
|
|
|
|
if (url.indexOf('data:') === 0)
|
|
|
|
{
|
|
|
|
videoType = url.split(',')[0].match(/\/(.*?);/);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
videoType = url.match(/\.([a-zA-Z0-9]+)($|\?)/);
|
|
|
|
}
|
|
|
|
|
|
|
|
videoType = GetFastValue(urls[i], 'type', (videoType) ? videoType[1] : '').toLowerCase();
|
|
|
|
|
|
|
|
if (Video[videoType])
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
url: url,
|
|
|
|
type: videoType
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2016-11-25 04:33:48 +00:00
|
|
|
return Video;
|
|
|
|
}
|
|
|
|
|
2016-11-26 01:28:53 +00:00
|
|
|
module.exports = init();
|