Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Adding background music that autostarts with application

$
0
0
I am trying to add background music that auto-starts when i run the processing sketch 
i followed a simple instruction online   and i added codes at line 6 , 26, 27,40,46 ,48, and from 75 to 82 
but i keep getting the error  "duplicate field name.player" at line 26 .

that said, can i use any mp3 file by specifying the file or does it have to be at a  specific bitrate ?

here's my code ,what am i doing wrong 

  1. import processing.serial.*;
  2. import processing.opengl.*;

  3. import ddf.minim.*;


  4. Serial serial;
  5. int serialPort = 1;   // << Set this to be the serial port of your Arduino - ie if you have 3 ports : COM1, COM2, COM3 
  6.                       // and your Arduino is on COM2 you should set this to '1' - since the array is 0 based
  7.               
  8. int sen = 3; // sensors
  9. int div = 3; // board sub divisions

  10. Normalize n[] = new Normalize[sen];
  11. MomentumAverage cama[] = new MomentumAverage[sen];
  12. MomentumAverage axyz[] = new MomentumAverage[sen];
  13. float[] nxyz = new float[sen];
  14. int[] ixyz = new int[sen];

  15. float w = 256; // board size
  16. boolean[] flip = {
  17.   false, true, false};
  18.   
  19. AudioPlayer player;
  20. Minim minim;

  21. int player = 0;
  22. boolean moves[][][][];

  23. PFont font;
  24. PImage b;


  25. void setup() {
  26.   size(1026, 770, P3D);
  27.   frameRate(25);
  28.   
  29.   minim = new Minim(this);
  30.   
  31.   // load a file, give the AudioPlayer buffers that are 1024 samples long
  32.   // player = minim.loadFile("groove.mp3");
  33.   
  34.   // load a file, give the AudioPlayer buffers that are 2048 samples long
  35.   player = minim.loadFile("groove.mp3", 2048);
  36.   // play the file
  37.   player.play();
  38.   
  39.   
  40.   b = loadImage("data/3.jpg");
  41.   font = loadFont("TrebuchetMS-Italic-20.vlw");
  42.   textFont(font);
  43.   textMode(SCREEN);
  44.   
  45.   println(Serial.list());
  46.   serial = new Serial(this, Serial.list()[serialPort], 115200);
  47.   
  48.   for(int i = 0; i < sen; i++) {
  49.     n[i] = new Normalize();
  50.     cama[i] = new MomentumAverage(.01);
  51.     axyz[i] = new MomentumAverage(.15);
  52.   }
  53.   
  54.   reset();
  55. }

  56. void draw() {
  57.   background(b);
  58.   
  59.   updateSerial();
  60.   drawBoard();
  61. }

  62. void stop()
  63. {
  64.   
  65.   player.close();
  66.   minim.stop();
  67.   
  68.   super.stop();
  69. }


...........continues 

any form of help would be much appreciated 

Viewing all articles
Browse latest Browse all 1768

Trending Articles