Minim, close sound file
              in 
             Core Library Questions 
              •  
              11 months ago    
            
 
           
             I am running out of memory very quickly, and I believe it may be related to my sound effects. I am using the following form..
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
             
            
            
 
            
           
             class Object {
            
            
                   AudioPlayer audio_sound;
            
            
                   //other values
            
            
                   Object( values ){
            
            
                   audio_sound = minim.loadFile("Sound.mp3");
            
            
                   //stuff
            
            
                   audio_sound.play();
            
            
                   }
            
            
                   void draw(){
            
            
                         //draw_object_stuff
            
            
                   }
            
            
             }
            
            
             I can't load the sound in setup because then it only plays once. If I try
            
            
                   audio_sound.close();
            
            
             after the draw() function has been called a set number of times then I get an error like this:
            
            
              Exception in thread "Animation Thread" java.lang.NullPointerException
             
             
               at ddf.minim.javasound.JSBaseAudioRecordingStream.close(Unknown Source)
             
             
               at ddf.minim.AudioPlayer.close(Unknown Source)
             
             
               at Laser_Ships_Building_Gui$Laser.draw(Laser_Ships_Building_Gui.java:424)
             
             
               at Laser_Ships_Building_Gui.draw(Laser_Ships_Building_Gui.java:483)
             
             
               at processing.core.PApplet.handleDraw(PApplet.java:2128)
             
             
               at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
             
             
               at processing.core.PApplet.run(PApplet.java:2006)
             
             
               at java.lang.Thread.run(Thread.java:662)
             
            
             How can I only load each sound once and get it to play multiple times, or close the file after it has been used effectively? 
            
 
            
              
              1  
            
 
            