Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

processing.js - Exporting a Processing sketch with audio to JavaScript

How could I implement sound in my Processing sketch that works when I export the sketch to JavaScript?

I've written a sketch in Processing that includes two audio (.wav) loops. These loops are played through the Movie class upon mousePressed() and mouseDragged(). The sketch works in normal/Java mode, but does not load when changed to JavaScript mode. The sketch only works in JavaScript mode when I remove the sound.

I've noticed that other sketches that use the Movie class as well as sketch examples of libraries such as Minim fail to load when I export them to JavaScript, so I think it's a problem with my implementation rather than the actual code.

I plan to ultimately use the sketch through Safari on an iPad.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For minim, you can use a relatively simple shim such as https://github.com/Pomax/Pjs-2D-Game-Engine/blob/master/minim.js - include it as a normal JS script on your page before loading any sketches, and your sketch won't complain that minim is an unknown thing.

Because Processing.js compiles your sketch to native JavaScript, global objects like Minim can simply be emulated in JavasScript as well: as long as the functions you're calling for Minim are defined in your JS "shim", things should work just fine.

On a more general note, because Processing libraries are precompiled Java VM byte code, Processing.js cannot load them, so any import statement is ignored.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...