-
Notifications
You must be signed in to change notification settings - Fork 1
/
SoundManagement.js
53 lines (42 loc) · 3.15 KB
/
SoundManagement.js
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
/// <reference path="Lib/knockout-3.1.0.js" />
/// <reference path="Lib/moment-2.8.4.min.js" />
/// <reference path="Lib/knockout-3.1.0.js" />
function SoundManagement(self) {
//Sounds
self.Beep = function () {
if (!self.SoundEnabled === true) return; //Sound will not work in tests
var cordovaMediaPluginAvailable = (typeof Media !== 'undefined');
if (cordovaMediaPluginAvailable)
self.PlayAudioCordova('beep1.mp3');
else {
var soundFile = document.getElementById("beepControl");
soundFile.load();
soundFile.play();
}
};
var alarmMasterBlinkOnSubscription;
self.StartAlarm = function () {
alarmMasterBlinkOnSubscription = self.MasterBlinkOn.subscribe(function () {
self.Beep();
});
};
self.StopAlarm = function () {
//Dispose the subscription that is bringing the beeping
if (alarmMasterBlinkOnSubscription) alarmMasterBlinkOnSubscription.dispose();
};
self.PlayAudioCordova = function (file) {
var p = window.location.pathname;
var root = p.substring(0, p.lastIndexOf('/')) + '/Sounds/';
var src = root + file;
var media = new Media(src,
// success callback
function () { },
// error callback
function (error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
);
media.play();
}
}