minim
我正在使用 Minim 进行处理,但如果加载文件在另一个类中,我无法弄清楚如何播放文件。我都用过AudioSnippet
,AudioSample
而且他们都给我NullPointerException
。这是一PlayAudio
堂课。
Minim minim;
AudioSample sample;
AudioSnippet snippet;
class PlayAudio {
PlayAudio() {
minim = new Minim(this);
sample = minim.loadSample("Audio/hover1.mp3", 2048);
snippet = minim.loadSnippet("Audio/hover1.mp3");
}
void playSnippet() {
sample.trigger();
snippet.play();
}
}
另一种是标准处理setup()
和draw()
。按下鼠标时应播放文件。
import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
PlayAudio audio = new PlayAudio();
void setup() {
size(300, 300);
background(0);
}
void draw() {
if(mousePressed) {
audio.playSnippet();
}
}
我得到的错误是:
==== JavaSound Minim Error ====
==== Couldn't find a sketchPath method on the file loading object provided!
==== File recording will be disabled.
==== JavaSound Minim Error ====
==== Couldn't find a createInput method in the file loading object provided!
==== File loading will be disabled.
==== JavaSound Minim Error ====
==== Error invoking createInput on the file loader object: null
=== Minim Error ===
=== Couldn't load the file Audio/hover1.mp3