Change entire audio code to maybe make iOS work right
This commit is contained in:
parent
0f993bb399
commit
ac55a3eee4
@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
echo "Replacing AppDelegate.m to fix AVAudioSession.Category..."
|
|
||||||
|
|
||||||
cp src/ios/AppDelegate.m platforms/ios/PackageHelper/Classes/AppDelegate.m
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
or more contributor license agreements. See the NOTICE file
|
|
||||||
distributed with this work for additional information
|
|
||||||
regarding copyright ownership. The ASF licenses this file
|
|
||||||
to you under the Apache License, Version 2.0 (the
|
|
||||||
"License"); you may not use this file except in compliance
|
|
||||||
with the License. You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
|
||||||
software distributed under the License is distributed on an
|
|
||||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
KIND, either express or implied. See the License for the
|
|
||||||
specific language governing permissions and limitations
|
|
||||||
under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//
|
|
||||||
// AppDelegate.m
|
|
||||||
// PackageHelper
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "AppDelegate.h"
|
|
||||||
#import "MainViewController.h"
|
|
||||||
#import <AVFoundation/AVFoundation.h>
|
|
||||||
|
|
||||||
@implementation AppDelegate
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
|
|
||||||
{
|
|
||||||
self.viewController = [[MainViewController alloc] init];
|
|
||||||
//set audio category to stop app interrupting music
|
|
||||||
NSError *setCategoryError = nil;
|
|
||||||
BOOL success = [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: &setCategoryError];
|
|
||||||
|
|
||||||
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -5,8 +5,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var sfx = {};
|
var sfx = {};
|
||||||
|
var sfxBuffers = {};
|
||||||
|
const AudioContext = window.AudioContext || window.webkitAudioContext;
|
||||||
|
var audioContext;
|
||||||
|
var sfxVolume = {
|
||||||
|
"alert": 100.0,
|
||||||
|
"ok": 100.0,
|
||||||
|
"error": 100.0,
|
||||||
|
"scan": 100.0
|
||||||
|
};
|
||||||
|
|
||||||
function initSFX() {
|
function initSFX() {
|
||||||
|
audioContext = new AudioContext();
|
||||||
if (getStorage("alertsound") == null) {
|
if (getStorage("alertsound") == null) {
|
||||||
setStorage("alertsound", "sonar");
|
setStorage("alertsound", "sonar");
|
||||||
}
|
}
|
||||||
@ -29,6 +39,46 @@ function initSFX() {
|
|||||||
"error": new Audio("assets/audio/error.mp3"),
|
"error": new Audio("assets/audio/error.mp3"),
|
||||||
"scan": new Audio("assets/audio/scan.mp3")
|
"scan": new Audio("assets/audio/scan.mp3")
|
||||||
};
|
};
|
||||||
|
if (noalertsound == false) {
|
||||||
|
window.fetch("assets/audio/" + alertNoiseFile)
|
||||||
|
.then(response => response.arrayBuffer())
|
||||||
|
.then(arrayBuffer => audioContext.decodeAudioData(arrayBuffer,
|
||||||
|
audioBuffer => {
|
||||||
|
sfxBuffers.alert = audioBuffer;
|
||||||
|
},
|
||||||
|
error =>
|
||||||
|
console.error(error)
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
sfxBuffers.alert = false;
|
||||||
|
}
|
||||||
|
window.fetch("assets/audio/ok.mp3")
|
||||||
|
.then(response => response.arrayBuffer())
|
||||||
|
.then(arrayBuffer => audioContext.decodeAudioData(arrayBuffer,
|
||||||
|
audioBuffer => {
|
||||||
|
sfxBuffers.ok = audioBuffer;
|
||||||
|
},
|
||||||
|
error =>
|
||||||
|
console.error(error)
|
||||||
|
));
|
||||||
|
window.fetch("assets/audio/error.mp3")
|
||||||
|
.then(response => response.arrayBuffer())
|
||||||
|
.then(arrayBuffer => audioContext.decodeAudioData(arrayBuffer,
|
||||||
|
audioBuffer => {
|
||||||
|
sfxBuffers.error = audioBuffer;
|
||||||
|
},
|
||||||
|
error =>
|
||||||
|
console.error(error)
|
||||||
|
));
|
||||||
|
window.fetch("assets/audio/scan.mp3")
|
||||||
|
.then(response => response.arrayBuffer())
|
||||||
|
.then(arrayBuffer => audioContext.decodeAudioData(arrayBuffer,
|
||||||
|
audioBuffer => {
|
||||||
|
sfxBuffers.scan = audioBuffer;
|
||||||
|
},
|
||||||
|
error =>
|
||||||
|
console.error(error)
|
||||||
|
));
|
||||||
|
|
||||||
setVolume("alert", alertVolume);
|
setVolume("alert", alertVolume);
|
||||||
}
|
}
|
||||||
@ -39,13 +89,18 @@ function initSFX() {
|
|||||||
* @returns {undefined}
|
* @returns {undefined}
|
||||||
*/
|
*/
|
||||||
function playSound(sound) {
|
function playSound(sound) {
|
||||||
if (sfx[sound] == false) {
|
if (sfxBuffers[sound] == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sfx[sound].volume == 0) {
|
if (sfxVolume[sound] == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sfx[sound].play();
|
const source = audioContext.createBufferSource();
|
||||||
|
source.buffer = sfxBuffers[sound];
|
||||||
|
const gainNode = audioContext.createGain();
|
||||||
|
gainNode.gain.value = sfxVolume[sound] / 100.0;
|
||||||
|
source.connect(gainNode).connect(audioContext.destination);
|
||||||
|
source.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +112,8 @@ function setVolume(sound, volume) {
|
|||||||
if (sfx[sound] == false) {
|
if (sfx[sound] == false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sfx[sound].volume = volume / 100.0;
|
//sfx[sound].volume = volume / 100.0;
|
||||||
|
sfxVolume[sound] = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
initSFX();
|
initSFX();
|
Loading…
x
Reference in New Issue
Block a user