forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio.js
More file actions
139 lines (115 loc) · 3.41 KB
/
Copy pathAudio.js
File metadata and controls
139 lines (115 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var OS = require('./OS');
var Browser = require('./Browser');
var Audio = {
/**
* @property {boolean} audioData - Are Audio tags available?
* @default
*/
audioData: false,
/**
* @property {boolean} webAudio - Is the WebAudio API available?
* @default
*/
webAudio: false,
/**
* @property {boolean} ogg - Can this device play ogg files?
* @default
*/
ogg: false,
/**
* @property {boolean} opus - Can this device play opus files?
* @default
*/
opus: false,
/**
* @property {boolean} mp3 - Can this device play mp3 files?
* @default
*/
mp3: false,
/**
* @property {boolean} wav - Can this device play wav files?
* @default
*/
wav: false,
/**
* Can this device play m4a files?
* @property {boolean} m4a - True if this device can play m4a files.
* @default
*/
m4a: false,
/**
* @property {boolean} webm - Can this device play webm files?
* @default
*/
webm: false,
/**
* @property {boolean} dolby - Can this device play EC-3 Dolby Digital Plus files?
* @default
*/
dolby: false
};
function init ()
{
Audio.audioData = !!(window['Audio']);
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
// bit.ly/iphoneoscodecs
if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, ''))
{
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;
}
module.exports = init();