The sound file does not loop

edited March 2018 in Library Questions

Hi Community,

I have got a problem that my sound file can't loop! I tried decreasing the bitrate, which does not work.

Help somebody could help me! Thank you very much!!!!

Here is my main tab! My classes are too long and maybe not related to the sound loop problem.So i did not include them.If the main tab does not have any question,i will go to check my classes.

import g4p_controls.*;
PImage back;

import processing.sound.*; 
SoundFile BGM;


void setup() {
  size(1800, 1000);
  back= loadImage("background13.png");
  textAlign(CENTER, CENTER);
  imageMode(CENTER);
  iniTial();
  createGUI();
  BGM = new SoundFile (this,"BGM.mp3"); 
  BGM.loop();
}


void draw() {
  background(255, 255, 255);
  drawBackground();
  keepersActivity();
  ballActivity();
  winSign();
  chaser_gryffindoActivity();
  chaser_slytherinActivity();

}
Tagged:

Answers

  • Please use the minim library instead and see if that works for you. You can start by checking the examples that comes with the library. Make a small sketch just testing its functionality before you add it to your main code.

    Kf

  • edited March 2018

    Thank you very much,KF!I' ve tried the minim library, my BGM go to loop but it will break in the middle of the BGM, and loop from the start of the BGM. My BGM can't run to end, it always stopped in the middle and loop from the beginning.

    I've no idea why.

    import ddf.minim.*;
    
    Minim minim;
    AudioPlayer BGM;
    
    void setup()
    {
      size(200, 200);
    
      minim = new Minim(this);
      BGM = minim.loadFile("BGM.mp3");
      BGM.loop();
      BGM.rewind();
    }
    
    void draw()
    {
      background(0);  
      stroke(255);
    }
    
  • why the rewind on line 13?

    the one thing we can't test is your mp3 file because we don't have it. maybe it's corrupt. but remove the rewind first.

  • Thank you koogs . I remove the rewind() now, but it still stops in the middle and loop from the beginning. I am sure the mp3 file is fine, cause if I delete BGM.loop() and use BGM.play(). I can play my BGM.mp3 from start to the end. However, Which can't loop. It's so weird.

    as you can see, I have the comment here, are two versions of the code.

    the loop() one, but stopped in the middle.

    import ddf.minim.*;
    
    Minim minim;
    AudioPlayer BGM;
    
    void setup()
    {
      size(200, 200);
    
      minim = new Minim(this);
      BGM = minim.loadFile("BGM.mp3");
      BGM.loop();
    }
    
    void draw()
    {
      background(0);  
    
    }
    

    The play() one,not loop ,but can be played in full.

    import ddf.minim.*;
    
    Minim minim;
    AudioPlayer BGM;
    
    void setup()
    {
      size(200, 200);
    
      minim = new Minim(this);
      BGM = minim.loadFile("BGM.mp3");
      BGM.play();
    }
    
    void draw()
    {
      background(0);  
    
    }
    

    Please tell me how to fix it ,thanks.

  • Answer ✓

    Try it with another file.

Sign In or Register to comment.