question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Play audio files in production

See original GitHub issue

I’ve been trying to follow the advice in #250 to configure playing audio files. That issue was mostly about image files. I added the following to webpack.config.base, inside module: rules: [

{
            test: /\.wav$|\.mp3$/,
            exclude: /node_modules/,
            loader: 'file-loader'
        }

I placed the audio files into an app/audio folder. I was able to import audio using either: import mySound from ‘audio/mySound.wav’ import mySound from ‘…/audio/mySound.wav’ Both work in a developer build. Neither works in the production build, raising a file not found error. I even see the corresponding .wav file in the /dist folder, but don’t know how to reference the correct path in the code. It looks like the HTTP get is trying to find the file in a /dist directory within the current router path.

In a developer build, I can also use: new Audio(path.resolve(‘./app/audio/mySound.wav’)) This also doesn’t work in a production build.

I’ve tried lots of different combinations of path names, but none seem to work. This seems like a common use case. But I can’t find any documentation, or StackOverflow guidance, on how to correctly import (or read) an audio file that will consistently work in both developer and production builds.

Is import the preferred way? If not, where should I place the audio files and how do I get them into the build process? Do I need to specify different paths for developer vs. production?

Thanks very much for your help, and your extremely useful boilerplate.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
amilajackcommented, Jun 20, 2018

Made this example for you. Hope it helps. It took some time to put together this example. A donation would be nice 😃

1reaction
jsrhomecommented, Jul 24, 2018

I found that I could import the audio file, construct a path name relative to the app.asar/dist folder, and then use that path name for the Audio() constructor. I needed to add a webpack file-loader for audio files (in my case, it is a .wav file). Then I use the code similar to:

import audioSrc from '..\audio\myAudio.wav'const resourcesPath = process.resourcesPath; let audioFileName, audioPath, sound; audioFileName = path.basename(audioSrc); if(isElectron()) { audioPath = path.resolve(resourcesPath, './app.asar/dist/' + audioFileName); sound = new Audio(audioPath); }

There has to be a better way, but this way worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I store audio files in production? - GoRails
I've already decided to use something like SoundManager or Plyr to actually play the audio clips, but I'm not sure how to store...
Read more >
7. Unit Two, Part Three: Types of Audio Files
People that work in audio production need to know the differences between varying digital and analog files, how to convert one to another,...
Read more >
Preparing Files for Delivery to Audio Post-Production
Cleanly organize & group the audio within your editing software so it contains all Production Audio for every video clip, Score (or Temp...
Read more >
Audio Assets | Switcher Studio Help Center
You can import audio files and create audio assets in Switcher Studio to enhance your production with sound effects and music.
Read more >
What's the Right Distribution Format for Your Finished Audio ...
For all types of audio productions, there comes a time when you finally need to mix all, independent recorded tracks down to one,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found