diff --git a/frontend/src/features/playScenario/PlayScenarioPage.jsx b/frontend/src/features/playScenario/PlayScenarioPage.jsx
index f49f7a43..a6378560 100644
--- a/frontend/src/features/playScenario/PlayScenarioPage.jsx
+++ b/frontend/src/features/playScenario/PlayScenarioPage.jsx
@@ -12,6 +12,7 @@ import { applyStateOperations } from "../../components/StateVariables/stateOpera
import NotesPanel from "./components/NotesPanel";
import ResourcesPanel from "./components/ResourcesPanel";
import SceneTimer from "./components/SceneTimer";
+import { PlayIcon } from "lucide-react";
const sceneCache = new Map();
@@ -83,6 +84,23 @@ const navigateMultiplayer = async (
};
};
+function playAudios(scene) {
+ const audios = scene.components.filter((c) => c.type === "audio");
+ const playables = [];
+ for (const audio of audios) {
+ const playable = new Audio(audio.url);
+ playable.loop = audio.loop;
+ playable.play();
+ playables.push(playable);
+ }
+ return () => {
+ for (const p of playables) {
+ p.pause();
+ p.currentTime = 0;
+ }
+ };
+}
+
/**
* This page allows users to play a scenario.
*
@@ -107,6 +125,7 @@ export default function PlayScenarioPage({ group }) {
const [resourcesOpen, setResourcesOpen] = useState(false);
const [noteOpen, setNoteOpen] = useState(false);
+ const [audioAllowed, setAudioAllowed] = useState(false);
const currScene = sceneCache.get(sceneId);
@@ -284,6 +303,16 @@ export default function PlayScenarioPage({ group }) {
onSceneChange();
};
+ useEffect(() => {
+ if (!currScene || !audioAllowed) return;
+ try {
+ const endPlayback = playAudios(currScene);
+ return () => endPlayback();
+ } catch {
+ toast.error("The audio on this scene failed to play");
+ }
+ }, [currScene, audioAllowed]);
+
if (loading) return