Comments (7)
this might get resolved soon.
There are a couple of PRs that relate to this.
processing/p5.js#5569
DefinitelyTyped/DefinitelyTyped#58331
from p5-typescript-starter.
@ihateids for now maybe just define he missing method at the top of your sketch.ts
file.
declare function loadSound(path: string): p5.SoundFile;
Let me know how you get on.
from p5-typescript-starter.
There is currently some missing global typings with regards to the sound
and dom
addons.
// won't work
mySound = loadSound('assets/doorbell');
// try this instead
mySound = new p5.SoundFile('assets/doorbell');
Documentation here: https://p5js.org/reference/#/p5.SoundFile
More information on the issue here: p5-types/p5.ts#16
Hope this helps. Let me know if you need more information :)
from p5-typescript-starter.
Thank you for the quick update. I tried the proposed solution, but it has a small drawback. The 'new p5.SoundFile' will load the sound in an asynchronous manner. It requires a callback to capture an event that the sound has been loaded.
The issue is, that after calling 'new p5.SoundFile', code will continue with P5 setup and draw function. If I want to play the sound in the setup function, for instance, the sound may not be loaded yet and the whole code breaks. I want to use it in preload function and trying to 'Promise'-fy it somehow did not work for me.
Since my aim is to use/share publicly available examples of how to use sound in P5, is there any suggested way how to preload sound without tricky hacks while using the suggested 'new p5.SoundFile', please?
from p5-typescript-starter.
@ihateids I think that the loadSound
works in the same way. In the p5 documentation is suggests putting the method inside the preload
function
function preload() {
mySound = new p5.SoundFile('assets/doorbell')
}
I think this is what you're looking for.
from p5-typescript-starter.
Unfortunately not. Let me try to depict the issue with a screenshot from firefox console:
and here is sample code:
let sound: p5.SoundFile;
function soundLoaded() {
console.log('Sound loaded');
}
// P5 will call this function to preload any assets (sounds, sprites, etc) and will continue with setup only when finished
function preload() {
sound = new p5.SoundFile('assets/ding.mp3', soundLoaded);
console.log('Preload finished');
}
function setup() {
console.log("π - Setup initialized - P5 is running");
createCanvas(windowWidth, windowHeight);
sound.play();
}
from p5-typescript-starter.
oh yes, that is the hack needed. Thank you so much for your help :)
from p5-typescript-starter.
Related Issues (13)
- Can't access p5.dom methods HOT 4
- werid typescript error HOT 2
- How do you import/use external libraries? HOT 3
- Missing properties of p5.color HOT 4
- SourceMap directory is incorrect HOT 3
- How to use clmtrackr HOT 6
- How to deploy it to a serverοΌ HOT 3
- Routing to mulitple Sketches HOT 2
- Require is not defined HOT 7
- Processing KEY constants are missing HOT 1
- createSlider seems to be undefined HOT 4
- Import destroys build HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p5-typescript-starter.