- remove native audio plugin references

- soundService for playing sounds
- file naming changed on sound files
- Bug where sounds were playing when mute switch on iPhone was on
- added cordova media plugin (with support for a fix the found mute-switch bug)
- play all sounds to use the new soundService
This commit is contained in:
Sebastiaan Pasma 2018-06-25 11:07:13 +02:00
commit 06ab1d1062
8 changed files with 46 additions and 34 deletions

View file

@ -72,7 +72,9 @@
<plugin name="cordova-plugin-queries-schemes" spec="~0.1.5" />
<plugin name="cordova-plugin-firebase" spec="https://github.com/arnesson/cordova-plugin-firebase.git" />
<plugin name="cordova-plugin-wkwebview-inputfocusfix" spec="https://github.com/onderceylan/cordova-plugin-wkwebview-inputfocusfix.git" />
<plugin name="cordova-plugin-nativeaudio" spec="^3.0.9" />
<plugin name="cordova-plugin-media" spec="~5.0.2">
<variable name="KEEP_AVAUDIOSESSION_ALWAYS_ACTIVE" value="NO" />
</plugin>
<!-- Changes in error descriptions may break the use of cordova-plugin-secure-storage -->
<plugin name="cordova-plugin-secure-storage" spec="2.6.8" />
<!-- Supported Platforms -->

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService) {
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, $stateParams, $window, $state, $log, profileService, bitcore, bitcoreCash, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, bwcError, txConfirmNotification, externalLinkService, firebaseEventsService, soundService) {
var countDown = null;
var FEE_TOO_HIGH_LIMIT_PER = 15;
@ -624,10 +624,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
(processName == 'sendingTx' && !$scope.wallet.canSign() && !$scope.wallet.isPrivKeyExternal())
) && !isOn) {
$scope.sendStatus = 'success';
if (config.soundsEnabled && $scope.wallet.coin == 'bch') {
var audio = new Audio('misc/bch_sent.mp3');
audio.play();
}
soundService.play('misc/payment_sent.mp3');
firebaseEventsService.logEvent('sent_bitcoin', { coin: $scope.wallet.coin });
$timeout(function() {
$scope.$digest();

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, txFormatService) {
angular.module('copayApp.controllers').controller('tabReceiveController', function($rootScope, $scope, $timeout, $log, $ionicModal, $state, $ionicHistory, $ionicPopover, storageService, platformInfo, walletService, profileService, configService, lodash, gettextCatalog, popupService, bwcError, bitcoinCashJsService, $ionicNavBarDelegate, txFormatService, soundService) {
var listeners = [];
$scope.bchAddressType = { type: 'cashaddr' };
@ -15,22 +15,6 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
var config;
var soundLoaded = false;
var nativeAudioAvailable = (window.plugins && window.plugins.NativeAudio);
if (nativeAudioAvailable) {
window.plugins.NativeAudio.preloadSimple('received', 'misc/coin_received.mp3', function (msg) {
$log.debug('Receive sound loaded.');
soundLoaded = true;
}, function (error) {
$log.debug('Error loading receive sound.');
$log.debug(error);
});
} else {
$log.debug('isNW: Using HTML5-Audio instead of native audio');
soundLoaded = true;
}
$scope.displayBalanceAsFiat = true;
$scope.requestSpecificAmount = function() {
@ -147,17 +131,7 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
}
$scope.paymentReceivedCoin = $scope.wallet.coin;
$scope.$apply(function () {
if (config.soundsEnabled && soundLoaded) {
$log.debug('Play sound.');
if (nativeAudioAvailable) {
window.plugins.NativeAudio.play('received');
} else {
new Audio('misc/coin_received.ogg').play(); // NW.js has no mp3 support
}
} else {
$log.debug('Sound is disabled.');
}
soundService.play('misc/payment_received.mp3');
$scope.showingPaymentReceived = true;
});
}

View file

@ -0,0 +1,39 @@
'use strict';
angular.module('copayApp.services').service('soundService', function($log, $timeout, platformInfo, configService) {
var root = {};
/**
* Play a sound (when enabled in the configuration) using the Cordova Media-plugin (on Mobile) or html5-audio (on Desktop) relative to the www-root
* Make sure there is a .ogg file as well for NW.js (desktop) implementation
* @param soundFile
*/
root.play = function(soundFile) {
configService.whenAvailable(function(config) {
if (config.soundsEnabled) {
if (platformInfo.isCordova) {
var p = window.location.pathname;
var device_path = p.substring(0, p.lastIndexOf('/'));
var audio = new Media(device_path + '/' + soundFile,
function () {
$log.debug("playAudio(bch_sent):Audio Success");
},
function (err) {
$log.debug("playAudio():Audio Error: " + err);
}
);
audio.play({playAudioWhenScreenIsLocked: false}); // XX SP: "Locked" is also the mute switch in iOS
} else {
if (platformInfo.isNW) {
soundFile = soundFile.substring(0, soundFile.lastIndexOf('.')) + ".ogg";
$log.debug("Playing .ogg file ("+soundFile+"), as NW.js has no mp3 support");
}
new Audio(soundFile).play();
}
}
});
};
return root;
});

BIN
www/misc/payment_sent.ogg Normal file

Binary file not shown.