im developing an electron app, which needs to play a sound in case of incoming message from webSocket connection. The websocket is handled on the main process, as the user switches pages during usage. I can not play the sound from the renderer, as i don't know in which page the user is at the moment, the webSocket message comes in (in worst case he is in between to pages while navigating).
Is there chance to play back audio on main process? The audio file is stored locally within the project file structure.
Kind regards,
BoxSon
I found this simple npm package for playing sounds without renderer, and
you can easily include it to your electron project.
Firstly, you need to install by npm install sound-play or save directly to your project with npm install sound-play --save and
initialize by this
const sound = require("sound-play");
and to play file just one line of code
sound.play("file.mp3");
You can learn more on the official site through this link
Found a workaround to solve this by my own:
create and open a hidden window.
In this window load a HTML5 audio player
via IPC send message to this hidden window from main to play a sound.
Little bit of effort but works like a charm.
Don't forget to destroy the hidden window on application closure (application won't close if you forget this step).
Related
I'd like to take a lot of screenshots and export .glb from thousands of generated a-frame models. Since I can't save files from the browser without prompt, generating the models on the server-side with node.js would be awesome.
(As a workaround I could probably generate the models in the browser and POST them to a local server that saves the files to disk but I'd prefer the server-side rendering if possible)
So, how can I render A-Frame models in node.js?
Tried approaches like this with mock-browser for mocking the DOM (which is necessary in three, let alone DOM-based a-frame) and headless-gl for creating a WebGL context in node.
No luck there, so I settled with an electron application.
tldr: check this out. Download, npm install; npm run start; and render screenshots / export the scene as glb. If you like it, let me know how to improve it to make it more useful.
non tldr:
You can load up an a-frame website using electron, but use the main process to save the screenshot on your drive - so there are no prompts, and it can be automated.
To make a render, You can simply use the native screenshot component to create a canvas containing the screenshot image
document.querySelector('a-scene').components.screenshot.getCanvas('equirectangular');
but instead of downloading the blob, pass it into the main process via an renderer to main IPC channel - where you can save it on your drive.
The actual task is to play mp3 file that should be embedded with the electron app.
I placed the mp3 file near my electron app "main.js".
I wanted to play it using some "sound-play" (https://github.com/nomadhoc/sound-play) package using bridge api, but it didn't worked out, sound is not playing.
So I want to just play it using an audio element (which seems to be more universal), but I don't get what src url I should supply to it. And then I wonder how to correctly add an additional asset to the built version (I'm using electron-builder).
Working with extra/local resources in election apps is kind of obscure topic for me. Advice would be appreciated.
I'm developing an electron application and the thing I don't understand is how apps like visual studio code achieve so fast startup times, by that I mean the time between clicking the icon until a window opens (until main.js gets loaded).
I already read many articles about speeding up electron but they all just talk about the stuff that happens AFTER main.js is loaded.
I downloaded the electron-quick-start example and packaged it using electron-builder as portable app.
Visual Studio Code: 1-2 secs until a window shows up
electron-quick-start: 5-10 secs
I was just wondering where the performance issue is, portable? electron-builder?
I found an issue in electron-builder that seems to indicate, that portable apps are extracted into a temp folder on app start, thats whats slow
Just to close this question:
Problem:
As indicated in the comments, the problem really is the portable mode of electron-builder. Portable Apps first unpack themselves into a temporary folder on your computer which can be a cpu intensive task because of compression.
Only after the app files have been unpacked, the main.js is actually loaded by node / electron.
Solutions:
Use an installer
When using an installer, the unpacking is done during installation of course, and not every time the app is started.
Use a splashimage (untested)
Although it is nowhere mentioned in the electron-builder docs, the code seems to indicate that you can set a splashImage bmp option:
https://github.com/electron-userland/electron-builder/blob/master/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts
/**
* The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image.
*/
readonly splashImage?: string | null
That would at least make it clear something is happening, instead of the user clicking the icon multiple times because the app doesn't open
I'm new to react native and building an audio streaming app. I found quite a few react native wrappers for native modules for playing audio files https://js.coach/react-native/react-native-ios-audio?search=audio
But none of them seem sufficient. I'm looking for a module that would
allow playing in the background and handle interruptions
have play-speed control
allow both streaming and local file playing
Does such a module exist? Any tips would be much appreciated. Thanks!
If your intention is to use the features you mentioned in a cross-platform (android/ios) app, then you do have some options, but there isn't a single module that will cover each of those bases.
Right now, I'm using a few different modules to accomplish similar functionality to what you're looking for:
react-native-audio-streaming to stream audio from a remote URL.
react-native-sound to play local audio files.
react-native-audio-streamer to stream audio from a remote URL on Android, since it uses ExoPlayer, instead of the AACDecoder used by react-native-audio-streaming.
Support for loading sound over the network was recently added to react-native-sound for iOS, and someone has mentioned the possibility of implementing it on Android as well. If this happens, then it may be the best choice for your use case.
I've included the current react-native-sound feature set below. Hope this helps!
Try Following Modules.
react-native-audio-streaming
react-native-audio-streamer
Has anyone used soundjs within a node webkit application using local mp3 files?
Can it be done? If so I will keep researching.
I have test apps that work through a browser (Chrome) playing my MP3 library with it but I cannot update my local library within javascript in an HTML5 page in my browser. As browsers block that.
So to get persistence I moved to a local app with node webkit and can do everything I want except successfully install soundjs.
Can it be done? If so I will keep researching.
The soundjs I am talking about is the one at http://createjs.com/Docs/SoundJS/modules/CreateJS.html
not the soundjs you install with npm. That is a module to access Soundcloud.
PS this is hobby fun stuff not real world stuff.
PPS I am working on Windows 8.1 just to make it harder!