Skip to content

Commit 92479eb

Browse files
committed
* Device.safariVersion now holds the major version of the Safari browser.
* Device.edge is a boolean that is set if running under the Microsoft Edge browser. * Device.dolby is a boolean that is set if the browser can play EC-3 Dolby Digital Plus files * The Loader and SoundManager can now play Dolby Digital Plus files on supported devices.
1 parent 332fb6f commit 92479eb

2 files changed

Lines changed: 60 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
313313
* The Grunt script has been updated to enhance the intro / outro and Pixi defaults. Pixi has been split into intro / outro and main blocks, so you can exclude its intro cleanly. The excludes are now bound, so if you exclude the Phaser UMD it will do the same for Pixi as well (thanks @spayton #2192)
314314
* ArcadePhysics.worldAngleToPointer will get the angle (in radians) between a display object and the pointer, taking all parent rotations into account (thanks @mattrick16 #2171)
315315
* There is new documentation on building Phaser for Webpack and a new custom build grunt option (thanks @deiga #2331)
316+
* Device.safariVersion now holds the major version of the Safari browser.
317+
* Device.edge is a boolean that is set if running under the Microsoft Edge browser.
318+
* Device.dolby is a boolean that is set if the browser can play EC-3 Dolby Digital Plus files
319+
* The Loader and SoundManager can now play Dolby Digital Plus files on supported devices.
316320

317321
### Updates
318322

src/system/Device.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ Phaser.Device = function () {
310310
*/
311311
this.tridentVersion = 0;
312312

313+
/**
314+
* @property {boolean} edge - Set to true if running in Microsoft Edge browser.
315+
* @default
316+
*/
317+
this.edge = false;
318+
313319
/**
314320
* @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
315321
* @default
@@ -334,6 +340,12 @@ Phaser.Device = function () {
334340
*/
335341
this.safari = false;
336342

343+
/**
344+
* @property {number} safariVersion - If running in Safari this will contain the major version number.
345+
* @default
346+
*/
347+
this.safariVersion = 0;
348+
337349
/**
338350
* @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView
339351
* @default
@@ -397,6 +409,12 @@ Phaser.Device = function () {
397409
*/
398410
this.webm = false;
399411

412+
/**
413+
* @property {boolean} dolby - Can this device play EC-3 Dolby Digital Plus files?
414+
* @default
415+
*/
416+
this.dolby = false;
417+
400418
// Video
401419

402420
/**
@@ -896,9 +914,14 @@ Phaser.Device._initialize = function () {
896914
{
897915
device.opera = true;
898916
}
899-
else if (/Safari/.test(ua) && !device.windowsPhone)
917+
else if (/Safari\/(\d+)/.test(ua) && !device.windowsPhone)
900918
{
901919
device.safari = true;
920+
921+
if (/Version\/(\d+)\./.test(ua))
922+
{
923+
device.safariVersion = parseInt(RegExp.$1, 10);
924+
}
902925
}
903926
else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua))
904927
{
@@ -907,6 +930,10 @@ Phaser.Device._initialize = function () {
907930
device.tridentVersion = parseInt(RegExp.$1, 10);
908931
device.ieVersion = parseInt(RegExp.$3, 10);
909932
}
933+
else if (/Edge\/\d+/.test(ua))
934+
{
935+
device.edge = true;
936+
}
910937

911938
// Silk gets its own if clause because its ua also contains 'Safari'
912939
if (/Silk/.test(ua))
@@ -1051,6 +1078,29 @@ Phaser.Device._initialize = function () {
10511078
{
10521079
device.webm = true;
10531080
}
1081+
1082+
if (audioElement.canPlayType('audio/mp4;codecs="ec-3"') !== '')
1083+
{
1084+
if (device.edge)
1085+
{
1086+
device.dolby = true;
1087+
}
1088+
else if (device.safari && device.safariVersion >= 9)
1089+
{
1090+
var ua = navigator.userAgent;
1091+
1092+
if (/Mac OS X (\d+)_(\d+)/.test(navigator.userAgent))
1093+
{
1094+
var major = parseInt(RegExp.$1, 10);
1095+
var minor = parseInt(RegExp.$2, 10);
1096+
1097+
if ((major === 10 && minor >= 11) || major > 10)
1098+
{
1099+
device.dolby = true;
1100+
}
1101+
}
1102+
}
1103+
}
10541104
}
10551105
} catch (e) {
10561106
}
@@ -1188,9 +1238,9 @@ Phaser.Device._initialize = function () {
11881238

11891239
// Run the checks
11901240
_checkOS();
1241+
_checkBrowser();
11911242
_checkAudio();
11921243
_checkVideo();
1193-
_checkBrowser();
11941244
_checkCSS3D();
11951245
_checkDevice();
11961246
_checkFeatures();
@@ -1233,6 +1283,10 @@ Phaser.Device.canPlayAudio = function (type) {
12331283
{
12341284
return true;
12351285
}
1286+
else if (type === 'mp4' && this.dolby)
1287+
{
1288+
return true;
1289+
}
12361290

12371291
return false;
12381292

0 commit comments

Comments
 (0)