Search code examples
reactjsrestaudiouncnwjs

How to load external sound files to a nwjs react project - cache them?


What are the possible solutions this problem: I need to include various sound files to a react app (build into a kiosk with nwjs) on app startup.

Let me explain the expected behavior - I have a nwjs kiosk react app that will run on a Windows machine.

  1. It should grab some UNC paths for sounds over rest api on app startup.
  2. I need to include these paths as resources (located outside the src folder) in the app in order to play the sounds.

Is it even possible?

Linking from the project's src folder is clear to me. But how to link paths outside the src folder when I don't even know the paths beforehand?

import OKSound from "./OK.wav";

Thank you!


Solution

  • Looks like there is no issue with playing sounds from "outside" with the audio tag, but it's really playing a sound only after creating an exe with nwjs!

    const url = "http://example.com/sound.wav";
    <audio autoPlay>
    <source src={url} type="audio/wav" />
    Your browser does not support the audio element.
    </audio>