From acd71caae273b973dc64b66072bb4afa3aae9efc Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 12 May 2017 14:53:38 +1200 Subject: [PATCH] Inform user when an AC error prevents a recording from playing --- scripts/system/playRecordingAC.js | 37 +++++++++++++++++++++++-------- scripts/system/record.js | 21 +++++++++++------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/scripts/system/playRecordingAC.js b/scripts/system/playRecordingAC.js index cc4c0345a9..5dab0c2ba0 100644 --- a/scripts/system/playRecordingAC.js +++ b/scripts/system/playRecordingAC.js @@ -14,6 +14,7 @@ var APP_NAME = "PLAYBACK", HIFI_RECORDER_CHANNEL = "HiFi-Recorder-Channel", + RECORDER_COMMAND_ERROR = "error", HIFI_PLAYER_CHANNEL = "HiFi-Player-Channel", PLAYER_COMMAND_PLAY = "play", PLAYER_COMMAND_STOP = "stop", @@ -69,12 +70,14 @@ if (sender !== scriptUUID) { message = JSON.parse(message); - index = otherPlayersPlaying.indexOf(message.entity); - if (index !== -1) { - otherPlayersPlayingCounts[index] += 1; - } else { - otherPlayersPlaying.push(message.entity); - otherPlayersPlayingCounts.push(1); + if (message.playing !== undefined) { + index = otherPlayersPlaying.indexOf(message.entity); + if (index !== -1) { + otherPlayersPlayingCounts[index] += 1; + } else { + otherPlayersPlaying.push(message.entity); + otherPlayersPlayingCounts.push(1); + } } } } @@ -270,14 +273,26 @@ playRecording; + function error(message) { + // Send error message to user. + Messages.sendMessage(HIFI_RECORDER_CHANNEL, JSON.stringify({ + command: RECORDER_COMMAND_ERROR, + message: message + })); + } + function play(recording, position, orientation) { + var errorMessage; + if (Entity.create(recording, position, orientation)) { - log("Play recording " + recordingFilename); + log("Play recording " + recording); isPlayingRecording = true; recordingFilename = recording; playRecording(recordingFilename, position, orientation); } else { - log("Could not play recording " + recordingFilename); + errorMessage = "Could not play recording " + recording.slice(4); // Remove leading "atp:". + log(errorMessage); + error(errorMessage); } } @@ -299,6 +314,8 @@ playRecording = function (recording, position, orientation) { Recording.loadRecording(recording, function (success) { + var errorMessage; + if (success) { Users.disableIgnoreRadius(); @@ -321,7 +338,9 @@ UserActivityLogger.logAction("playRecordingAC_play_recording"); } else { - log("Failed to load recording " + recording); + errorMessage = "Could not load recording " + recording.slice(4); // Remove leading "atp:". + log(errorMessage); + error(errorMessage); autoPlayTimer = Script.setTimeout(autoPlay, AUTOPLAY_ERROR_INTERVAL); // Try again later. } }); diff --git a/scripts/system/record.js b/scripts/system/record.js index f9936942fb..1c36a122b9 100644 --- a/scripts/system/record.js +++ b/scripts/system/record.js @@ -269,6 +269,7 @@ Player = (function () { var HIFI_RECORDER_CHANNEL = "HiFi-Recorder-Channel", + RECORDER_COMMAND_ERROR = "error", HIFI_PLAYER_CHANNEL = "HiFi-Player-Channel", PLAYER_COMMAND_PLAY = "play", PLAYER_COMMAND_STOP = "stop", @@ -350,15 +351,19 @@ message = JSON.parse(message); - index = playerIDs.indexOf(sender); - if (index === -1) { - index = playerIDs.length; - playerIDs[index] = sender; + if (message.command === RECORDER_COMMAND_ERROR) { + error(message.message); + } else { + index = playerIDs.indexOf(sender); + if (index === -1) { + index = playerIDs.length; + playerIDs[index] = sender; + } + playerIsPlayings[index] = message.playing; + playerRecordings[index] = message.recording; + playerTimestamps[index] = Date.now(); + Dialog.updatePlayerDetails(playerIsPlayings, playerRecordings, playerIDs); } - playerIsPlayings[index] = message.playing; - playerRecordings[index] = message.recording; - playerTimestamps[index] = Date.now(); - Dialog.updatePlayerDetails(playerIsPlayings, playerRecordings, playerIDs); } function reset() {