Stop and play audio with mouse pressed
in
Core Library Questions
•
6 months ago
Hello to all the community, would like to help me create a button that when you click with the mouse to the music itself, and another that did continue.
Thank people!
This is my code:
Thank people!
This is my code:
- import ddf.minim.*;
- import ddf.minim.analysis.*;
- import ddf.minim.analysis.*;
- import processing.opengl.*;
- import javax.media.opengl.*;
- import netscape.javascript.*;
- import processing.video.*
- Bola bolinhas[];
- PImage bg;
- PImage imagemparticula;
- PGraphicsOpenGL pgl;
- GL gl;
- MovieMaker mm;
- Minim minim;
- AudioPlayer musica;
- FFT fft;
- void setup() {
- size(800, 600, OPENGL);
- //mm = new MovieMaker(this, width, height, "hiphop_processing.mov",30, MovieMaker.H263,
- MovieMaker.HIGH);
- mm = null;
- bg = loadImage("fundo.png");
- imagemparticula = loadImage("particula.png");
- minim = new Minim(this);
- musica = minim.loadFile("music.mp3");
- musica.play();
- musica.loop();
- fft = new FFT(musica.bufferSize(), musica.sampleRate());
- bolinhas = new Bola [fft.specSize()];
- for (int i=0; i<bolinhas.length; i++) {
- bolinhas[i] = new Bola();
- }
- hint(DISABLE_DEPTH_TEST);
- background( 0 );
- image( bg, 0, 0, width, height);
- }
- void draw() {
- //background(bg);
- fill( 0, 30 );
- //image( bg, 0, 0, width, height );
- rect( 0, 0, width, height );
- image( bg, 0, 0, width, height);
- fft.forward(musica.mix);
- float centroX = width / 2;
- float centroY = height / 2;
- pgl = (PGraphicsOpenGL) g;
- gl = pgl.beginGL();
- gl.glEnable(GL.GL_BLEND);
- gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
- pgl.endGL();
-
- fill(255);
- text("Press space to record a video", 20, 20);
- for (int i=0; i<bolinhas.length; i++) {
- bolinhas[i].mover();
- bolinhas[i].desenhar();
- bolinhas[i].elastico(centroX, centroY, 100);
- float val = fft.getBand( i ) + 1;
- float forcaX = random( -val, val );
- float forcaY = random( -val, val );
- bolinhas[i].forca(forcaX, forcaY);
- }
- if ( mm != null ) {
- mm.addFrame();
- }
- }
- void keyPressed() {
- if (key == ' ') {
- if ( mm == null ) {
- mm = new MovieMaker(this, width, height, "hiphop_processing.mov",30,
- MovieMaker.H263, MovieMaker.HIGH);
- }
- else {
- mm.finish(); // Finish the movie if space bar is pressed!
- }
- }
- }
1