Play sounds during countdown and beep when recording starts and finishes

This commit is contained in:
David Rowe 2017-04-14 10:34:15 +12:00
parent 072e06123f
commit fd919f0db7
4 changed files with 39 additions and 35 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -21,7 +21,6 @@
button, button,
isConnected, isConnected,
CountdownTimer,
RecordingIndicator, RecordingIndicator,
Recorder, Recorder,
Player, Player,
@ -37,37 +36,6 @@
} }
CountdownTimer = (function () {
// Counts down a few seconds.
var countdownTimer,
countdownSeconds,
COUNTDOWN_SECONDS = 3,
finishCallback;
function start(onFinishCallback) {
finishCallback = onFinishCallback;
countdownSeconds = COUNTDOWN_SECONDS;
countdownTimer = Script.setInterval(function () {
countdownSeconds -= 1;
if (countdownSeconds <= 0) {
Script.clearInterval(countdownTimer);
finishCallback();
} else {
// TODO: Tick.
}
}, 1000);
}
function cancel() {
Script.clearInterval(countdownTimer);
}
return {
start: start,
cancel: cancel
};
}());
RecordingIndicator = (function () { RecordingIndicator = (function () {
// Displays "recording" overlay. // Displays "recording" overlay.
@ -139,7 +107,27 @@
mappingPath, mappingPath,
startPosition, startPosition,
startOrientation, startOrientation,
play; play,
countdownTimer,
countdownSeconds,
COUNTDOWN_SECONDS = 3,
tickSound,
startRecordingSound,
finishRecordingSound,
TICK_SOUND = "assets/sounds/countdown-tick.wav",
START_RECORDING_SOUND = "assets/sounds/start-recording.wav",
FINISH_RECORDING_SOUND = "assets/sounds/finish-recording.wav",
SOUND_VOLUME = 0.2;
function playSound(sound) {
Audio.playSound(sound, {
position: MyAvatar.position,
localOnly: true,
volume: SOUND_VOLUME
});
}
function setMappingCallback(status) { function setMappingCallback(status) {
if (status !== "") { if (status !== "") {
@ -174,6 +162,7 @@
function startRecording() { function startRecording() {
recordingState = RECORDING; recordingState = RECORDING;
log("Start recording"); log("Start recording");
playSound(startRecordingSound);
startPosition = MyAvatar.position; startPosition = MyAvatar.position;
startOrientation = MyAvatar.orientation; startOrientation = MyAvatar.orientation;
Recording.startRecording(); Recording.startRecording();
@ -186,6 +175,7 @@
recordingState = IDLE; recordingState = IDLE;
log("Finish recording"); log("Finish recording");
playSound(finishRecordingSound);
Recording.stopRecording(); Recording.stopRecording();
RecordingIndicator.hide(); RecordingIndicator.hide();
success = Recording.saveRecordingToAsset(saveRecordingToAssetCallback); success = Recording.saveRecordingToAsset(saveRecordingToAssetCallback);
@ -208,14 +198,24 @@
function cancelCountdown() { function cancelCountdown() {
recordingState = IDLE; recordingState = IDLE;
CountdownTimer.cancel(); Script.clearInterval(countdownTimer);
log("Cancel countdown"); log("Cancel countdown");
} }
function startCountdown() { function startCountdown() {
recordingState = COUNTING_DOWN; recordingState = COUNTING_DOWN;
log("Start countdown"); log("Start countdown");
CountdownTimer.start(finishCountdown); playSound(tickSound);
countdownSeconds = COUNTDOWN_SECONDS;
countdownTimer = Script.setInterval(function () {
countdownSeconds -= 1;
if (countdownSeconds <= 0) {
Script.clearInterval(countdownTimer);
finishCountdown();
} else {
playSound(tickSound);
}
}, 1000);
} }
function isIdle() { function isIdle() {
@ -232,6 +232,10 @@
function setUp(playerCallback) { function setUp(playerCallback) {
play = playerCallback; play = playerCallback;
tickSound = SoundCache.getSound(Script.resolvePath(TICK_SOUND));
startRecordingSound = SoundCache.getSound(Script.resolvePath(START_RECORDING_SOUND));
finishRecordingSound = SoundCache.getSound(Script.resolvePath(FINISH_RECORDING_SOUND));
} }
function tearDown() { function tearDown() {