问题描述
我正在使用Minim进行处理,但是如果minim
加载文件在另一个类中,则我无法弄清楚如何播放文件.我同时使用了AudioSnippet
和AudioSample
,它们都给了我NullPointerException
.这是PlayAudio
类.
I am using processing with Minim, but I can't figure out how to play files, if the minim
loading files are in another class. I used both AudioSnippet
and AudioSample
and they both give me NullPointerException
. Here is a the PlayAudio
class.
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()
.按下鼠标时应播放文件.
The other is a standard processing setup()
and draw()
. Files should be played when mouse is pressed.
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
推荐答案
只需将 minim = new Minim( this ); 放入设置堵塞.如果您在PlayAudio类中执行此操作,则您得到的 this 参数错误.
Just put minim = new Minim( this ); into setup block. If you do this inside PlayAudio class you get wrong argument for this.
工作代码:
import ddf.minim.*;
Minim minim;
AudioSample sample;
AudioSnippet snippet;
PlayAudio audio;
void setup() {
size(300, 300);
minim = new Minim(this);
audio = new PlayAudio();
background(0);
}
void draw() {
if (mousePressed) {
audio.playSnippet();
}
}
class PlayAudio {
PlayAudio() {
sample = minim.loadSample("Audio/hover1.mp3", 2048);
snippet = minim.loadSnippet("Audio/hover1.mp3");
}
void playSnippet() {
sample.trigger();
snippet.play();
}
}
这篇关于处理最小空指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!