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
|
|
|
*/
|
|
|
|
|
2016-11-26 01:28:53 +00:00
|
|
|
var Browser = require('./Browser');
|
|
|
|
|
2018-01-25 17:03:35 +00:00
|
|
|
/**
|
|
|
|
* Determines the audio playback capabilities of the device 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.audio` from within any Scene.
|
2020-10-05 16:12:09 +00:00
|
|
|
*
|
2018-03-28 14:04:09 +00:00
|
|
|
* @typedef {object} Phaser.Device.Audio
|
2018-01-25 17:03:35 +00:00
|
|
|
* @since 3.0.0
|
2020-10-05 16:12:09 +00:00
|
|
|
*
|
2018-01-25 17:03:35 +00:00
|
|
|
* @property {boolean} audioData - Can this device play HTML Audio tags?
|
|
|
|
* @property {boolean} dolby - Can this device play EC-3 Dolby Digital Plus files?
|
|
|
|
* @property {boolean} m4a - Can this device can play m4a files.
|
|
|
|
* @property {boolean} mp3 - Can this device play mp3 files?
|
|
|
|
* @property {boolean} ogg - Can this device play ogg files?
|
|
|
|
* @property {boolean} opus - Can this device play opus files?
|
|
|
|
* @property {boolean} wav - Can this device play wav files?
|
|
|
|
* @property {boolean} webAudio - Does this device have the Web Audio API?
|
|
|
|
* @property {boolean} webm - Can this device play webm files?
|
|
|
|
*/
|
2016-11-25 04:33:48 +00:00
|
|
|
var Audio = {
|
|
|
|
|
|
|
|
audioData: false,
|
2018-01-25 17:03:35 +00:00
|
|
|
dolby: false,
|
|
|
|
m4a: false,
|
|
|
|
mp3: false,
|
2016-11-25 04:33:48 +00:00
|
|
|
ogg: false,
|
|
|
|
opus: false,
|
|
|
|
wav: false,
|
2018-01-25 17:03:35 +00:00
|
|
|
webAudio: false,
|
|
|
|
webm: 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 Audio;
|
|
|
|
}
|
|
|
|
|
2016-11-25 04:33:48 +00:00
|
|
|
Audio.audioData = !!(window['Audio']);
|
2017-11-09 13:43:56 +00:00
|
|
|
|
2016-11-25 04:33:48 +00:00
|
|
|
Audio.webAudio = !!(window['AudioContext'] || window['webkitAudioContext']);
|
|
|
|
|
|
|
|
var audioElement = document.createElement('audio');
|
|
|
|
|
|
|
|
var result = !!audioElement.canPlayType;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ''))
|
|
|
|
{
|
|
|
|
Audio.ogg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '') || audioElement.canPlayType('audio/opus;').replace(/^no$/, ''))
|
|
|
|
{
|
|
|
|
Audio.opus = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, ''))
|
|
|
|
{
|
|
|
|
Audio.mp3 = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mimetypes accepted:
|
|
|
|
// developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
|
2020-10-05 16:12:09 +00:00
|
|
|
if (audioElement.canPlayType('audio/wav').replace(/^no$/, ''))
|
2016-11-25 04:33:48 +00:00
|
|
|
{
|
|
|
|
Audio.wav = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, ''))
|
|
|
|
{
|
|
|
|
Audio.m4a = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ''))
|
|
|
|
{
|
|
|
|
Audio.webm = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audioElement.canPlayType('audio/mp4;codecs="ec-3"') !== '')
|
|
|
|
{
|
|
|
|
if (Browser.edge)
|
|
|
|
{
|
|
|
|
Audio.dolby = true;
|
|
|
|
}
|
|
|
|
else if (Browser.safari && Browser.safariVersion >= 9)
|
|
|
|
{
|
|
|
|
if ((/Mac OS X (\d+)_(\d+)/).test(navigator.userAgent))
|
|
|
|
{
|
|
|
|
var major = parseInt(RegExp.$1, 10);
|
|
|
|
var minor = parseInt(RegExp.$2, 10);
|
|
|
|
|
|
|
|
if ((major === 10 && minor >= 11) || major > 10)
|
|
|
|
{
|
|
|
|
Audio.dolby = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
// Nothing to do here
|
|
|
|
}
|
|
|
|
|
|
|
|
return Audio;
|
|
|
|
}
|
|
|
|
|
2016-11-26 01:28:53 +00:00
|
|
|
module.exports = init();
|