本文介绍了将带有音频的处理草图导出到JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将草图导出到JavaScript时,如何在我的处理"草图中实现声音?

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

我在处理"中写了一个草图,其中包括两个音频(.wav)循环.这些循环通过mousePressed()mouseDragged()上的Movie类播放.草图可在正常/Java模式下工作,但在更改为JavaScript模式后不会加载.当我删除声音时,草图仅在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.

我注意到,使用Movie类的其他草图以及诸如Minim之类的库的草图示例在我将其导出到JavaScript时均无法加载,因此我认为这是我的实现而非实际问题代码.

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.

我计划最终通过iPad上的Safari使用草图.

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

谢谢.

推荐答案

对于最小化,您可以使用相对简单的填充程序,例如 https://github.com/Pomax/Pjs-2D-Game-Engine/blob/master/minim.js -将其作为加载任何草图之前,您页面上的普通JS脚本,草图不会抱怨minim是未知的事情.

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.

由于Processing.js将您的草图编译为本机JavaScript,因此Minim之类的全局对象也可以简单地在JavasScript中进行仿真:只要您要调用Minim的函数在您的JS垫片"中定义,事情就可以正常工作很好.

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.

更一般地说,由于处理库是预编译的Java VM字节码,Processing.js无法加载它们,因此任何导入语句都将被忽略.

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.

这篇关于将带有音频的处理草图导出到JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 04:22