2

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();
  }
}

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();
   }
}

The errors I get are:

==== 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
t0mppa
  • 3,983
  • 5
  • 37
  • 48
Silent Ace
  • 299
  • 1
  • 6
  • 20
  • 2
    Are you sure the file paths are correct? – Trojan Dec 28 '13 at 16:36
  • The variables `minim`, `sample`, and `snippet` aren't actually in your `PlayAudio` class. They're global variables, so there could be an initialisation order problem. Try putting them inside your `PlayAudio` class declaration. – Peter Bloomfield Jan 01 '14 at 16:41

1 Answers1

2

Just put minim = new Minim( this ); into setup block. If you do this inside PlayAudio class you get wrong argument for this.

Working code:

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();
  }
}
Jo Ja
  • 243
  • 4
  • 14
  • I've been reading about this, and the most confusing thing for me is that all examples look like yours, but WHEN are these methods called? - thanks – TootsieRockNRoll Oct 02 '17 at 13:40