java - Audio files won't stop playing when I go to next item in list -


here code:

public apjmenu createmenu(string menulabel, string[] menuitems) {     // create menu item passed in title     apjmenu menu = new apjmenu(menulabel, getsoundfilename(menulabel),             this.audiosourcetype);      apjmenuitem menuitem;     (int = 0; < menuitems.length; i++) {         menuitem = new apjmenuitem(menuitems[i],                 getsoundfilename(menuitems[i]), audiosourcetype);          menuitem.setenabled(true);         menuitem.addactionlistener(this);         menuitem.addmenukeylistener(this);         menuitem.setactioncommand(menuitems[i]);          menu.add(menuitem);     }      return menu; } 

this main program does. of audio files added menus enables audio playback. however, there referenced jar file communicates program , reads in text , makes calls play corresponding audio file. if run program, generate menu plays audio navigate item list.

apjmenuitem class

// referenced classes of package enhancedwidgets: apcomponent, apcomponentgenerics, apjframe  public class apjmenuitem extends jmenuitem     implements apcomponent, mouselistener, menukeylistener {      public apjmenuitem(string label) {         super(label);         type = default_sound_type;         visuals_enabled = true;         init(soundtypes.sound.soundtype.spearcon, label, null);     }      public apjmenuitem(string label, string filename, soundtypes.sound.soundtype type) {         super(label);         this.type = default_sound_type;         visuals_enabled = true;         init(type, label, filename);     }      private void init(soundtypes.sound.soundtype type, string label, string filename) {         this.type = type;         switch($switch_table$soundtypes$sound$soundtype()[type.ordinal()]) {         case 5: // '\005'             sound = new spearcon(label, null);             break;          case 1: // '\001'         case 3: // '\003'             sound = new auditoryicon(new file(filename));             break;          case 2: // '\002'         case 4: // '\004'         default:             sound = null;             break;         }         addmouselistener(this);         addmenukeylistener(this);     }      public void settext(string text) {         super.settext(text);         if(type == null)             type = default_sound_type;         init(type, text, null);     }      public void setfile(string filename) {         init(soundtypes.sound.soundtype.soundfile, gettext(), filename);     }      public void findsoundlistener() {         apcomponentgenerics.findsoundlistener(listener, this);         sound.setsoundlistener(listener);     }      public void updatesoundlistener(apjframe frame) {         listener = apcomponentgenerics.updatesoundlistener(frame);         sound.setsoundlistener(listener);     }      public boolean hassoundlistener() {         return apcomponentgenerics.hassoundlistener(listener);     }      public apcomponent.componenttype getcomponenttype() {         return apcomponent.componenttype.menuitem;     }      public boolean isapcomponent() {         return true;     }      public void mouseclicked(mouseevent mouseevent) {     }      public void mousepressed(mouseevent mouseevent) {     }      public void mousereleased(mouseevent mouseevent) {     }      public void mouseexited(mouseevent e) {         sound.stop();     }      public void mouseentered(mouseevent e) {         if(!hassoundlistener())             findsoundlistener();         (new thread(sound)).start();     }      public void menukeypressed(menukeyevent e) {         if(isarmed() && !sound.isstopped())             sound.stop();     }      public void menukeyreleased(menukeyevent e) {         if(isarmed()) {             if(!hassoundlistener())                 findsoundlistener();             (new thread(sound)).start();         }     }      public void menukeytyped(menukeyevent menukeyevent) {     }      public void setvisualsenabled(boolean enabled) {         visuals_enabled = enabled;     }      public boolean isvisualsenabled() {         return visuals_enabled;     }      protected void paintcomponent(graphics g) {         if(isvisualsenabled())             super.paintcomponent(g);     }      static int[] $switch_table$soundtypes$sound$soundtype() {         $switch_table$soundtypes$sound$soundtype;         if($switch_table$soundtypes$sound$soundtype == null) goto _l2; else goto _l1 _l1:         return; _l2:         jvm instr pop ;         int ai[] = new int[soundtypes.sound.soundtype.values().length];         try {             ai[soundtypes.sound.soundtype.auditoryicon.ordinal()] = 1;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.earcon.ordinal()] = 2;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.other.ordinal()] = 6;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.soundfile.ordinal()] = 3;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.soundscape.ordinal()] = 4;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.spearcon.ordinal()] = 5;         }         catch(nosuchfielderror _ex) { }         return $switch_table$soundtypes$sound$soundtype = ai;     }      private static final long serialversionuid = 0x77c71df3l;     sound sound;     soundlistener listener;     private static soundtypes.sound.soundtype default_sound_type;     soundtypes.sound.soundtype type;     private boolean visuals_enabled;     private static int $switch_table$soundtypes$sound$soundtype[];      static  {         default_sound_type = soundtypes.sound.soundtype.spearcon;     } } 

apjmenu class

// referenced classes of package enhancedwidgets: //            apcomponent, apcomponentgenerics, apjmenuitem, apjframe  public class apjmenu extends jmenu     implements mouselistener, menulistener, apcomponent, menukeylistener {      public apjmenu(string label) {         super(label);         listener = null;         frame = null;         visuals_enabled = true;         init(soundtypes.sound.soundtype.spearcon, label, null);     }      public apjmenu(string label, string filename, soundtypes.sound.soundtype type) {         super(label);         listener = null;         frame = null;         visuals_enabled = true;         init(type, label, filename);     }      private void init(soundtypes.sound.soundtype type, string label, string filename) {         this.type = type;         switch($switch_table$soundtypes$sound$soundtype()[type.ordinal()]) {         case 5: // '\005'             sound = new spearcon(label, null);             break;          case 1: // '\001'         case 3: // '\003'             sound = new auditoryicon(new file(filename));             break;          case 2: // '\002'         case 4: // '\004'         default:             sound = null;             break;         }         addmouselistener(this);         addmenulistener(this);     }      public void findsoundlistener() {         apcomponentgenerics.findsoundlistener(listener, this);         sound.setsoundlistener(listener);     }      public void updatesoundlistener() {         findsoundlistener();     }      public boolean hassoundlistener() {         return apcomponentgenerics.hassoundlistener(listener);     }      public void updatesoundlistener(apjframe frame) {         listener = apcomponentgenerics.updatesoundlistener(frame);         this.frame = frame;         sound.setsoundlistener(listener);     }      public void add(apjmenuitem menuitem) {         super.add(menuitem);         menuitem.updatesoundlistener(frame);         menuitem.addmenukeylistener(this);     }      public void add(apjmenu menu) {         super.add(menu);         menu.updatesoundlistener(frame);     }      public apcomponent.componenttype getcomponenttype() {         return apcomponent.componenttype.menu;     }      public boolean isapcomponent() {         return true;     }      public void menucanceled(menuevent e) {         if(!sound.isstopped())             sound.stop();     }      public void menudeselected(menuevent e) {         if(!sound.isstopped())             sound.stop();     }      public void menuselected(menuevent e) {         if(!hassoundlistener())             findsoundlistener();         if(!sound.isstopped())             sound.stop();         (new thread(sound)).start();         (new thread(sound)).start();     }      public void mouseclicked(mouseevent mouseevent) {     }      public void mousepressed(mouseevent mouseevent) {     }      public void mousereleased(mouseevent mouseevent) {     }      public void mouseexited(mouseevent e) {         sound.stop();     }      public void mouseentered(mouseevent e) {         if(!hassoundlistener())             findsoundlistener();         (new thread(sound)).start();     }      public void menukeypressed(menukeyevent e) {         if(!sound.isstopped())             sound.stop();     }      public void menukeyreleased(menukeyevent menukeyevent) {     }      public void menukeytyped(menukeyevent menukeyevent) {     }      public void setvisualsenabled(boolean enabled) {         visuals_enabled = enabled;     }      public boolean isvisualsenabled() {         return visuals_enabled;     }      protected void paintcomponent(graphics g) {         if(isvisualsenabled())             super.paintcomponent(g);     }      static int[] $switch_table$soundtypes$sound$soundtype() {         $switch_table$soundtypes$sound$soundtype;         if($switch_table$soundtypes$sound$soundtype == null) goto _l2; else goto _l1 _l1:         return; _l2:         jvm instr pop ;         int ai[] = new int[soundtypes.sound.soundtype.values().length];         try {             ai[soundtypes.sound.soundtype.auditoryicon.ordinal()] = 1;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.earcon.ordinal()] = 2;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.other.ordinal()] = 6;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.soundfile.ordinal()] = 3;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.soundscape.ordinal()] = 4;         }         catch(nosuchfielderror _ex) { }         try {             ai[soundtypes.sound.soundtype.spearcon.ordinal()] = 5;         }         catch(nosuchfielderror _ex) { }         return $switch_table$soundtypes$sound$soundtype = ai;     }      private static final long serialversionuid = 0xf123a728l;     sound sound;     soundlistener listener;     apjframe frame;     soundtypes.sound.soundtype type;     private boolean visuals_enabled;     private static int $switch_table$soundtypes$sound$soundtype[]; } 

sound class

package soundtypes;  import soundserver.soundlistener;  public abstract class sound     implements runnable {     /* member class not found */ class soundtype {}   public sound() { }  public abstract void play();  public abstract void stop();  public abstract soundtype getsoundtype();  public boolean isauditoryicon() {     return false; }  public boolean isearcon() {     return false; }  public boolean issoundfile() {     return false; }  public boolean issoundscape() {     return false; }  public boolean isspearcon() {     return false; }  public boolean isother() {     return false; }  public abstract boolean isstopped();  public boolean ismenusound(sound s) {     return s.isauditoryicon() || s.isearcon() || s.isspearcon(); }  public void setsoundlistener(soundlistener listener) {     this.listener = listener; }  protected soundlistener listener; 

}

soundfile class

package soundtypes;  import java.io.file; import java.io.ioexception; import java.net.malformedurlexception; import javax.sound.sampled.*; import soundserver.stopwatch;  // referenced classes of package soundtypes: //            sound  public class soundfile extends sound {  public soundfile(file file) {     stopped = true;     continuous = false;     gaincontrol = null;     playfrequency = 1.0d;     this.file = null;     volume = 0.0d;     second = false;     initialize(file); }  private void initialize(file file) {     this.file = file;     try {         stream = audiosystem.getaudioinputstream(file);         audioformat format = stream.getformat();         if(format.getencoding() != javax.sound.sampled.audioformat.encoding.pcm_signed) {             format = new audioformat(javax.sound.sampled.audioformat.encoding.pcm_signed, format.getsamplerate(), format.getsamplesizeinbits(), format.getchannels(), format.getframesize(), format.getframerate(), true);             stream = audiosystem.getaudioinputstream(format, stream);         }         javax.sound.sampled.dataline.info info = new javax.sound.sampled.dataline.info(javax/sound/sampled/clip, stream.getformat(), (int)stream.getframelength() * format.getframesize());         clip = (clip)audiosystem.getline(info);         try {             gaincontrol = (floatcontrol)clip.getcontrol(javax.sound.sampled.floatcontrol.type.master_gain);         }         catch(illegalargumentexception exception) {             gaincontrol = null;         }     }     catch(malformedurlexception e) {         e.printstacktrace();     }     catch(ioexception e) {         e.printstacktrace();     }     catch(lineunavailableexception e) {         e.printstacktrace();     }     catch(unsupportedaudiofileexception e) {         e.printstacktrace();     } }  public long getcliplengthms() {     boolean wasopen = clip.isopen();     if(!wasopen)         try {             clip.open(stream);         }         catch(lineunavailableexception e) {             e.printstacktrace();         }         catch(ioexception e) {             e.printstacktrace();         }     long length = clip.getmicrosecondlength();     if(!wasopen)         clip.close();     return length; }  public void setvolume(double percent) {     if(gaincontrol == null) {         return;     } else {         volume = percent;         float db = (float)((math.log(percent) / math.log(10d)) * 20d);         gaincontrol.setvalue(db);         return;     } }  public void setcontiuous(boolean continuous) {     this.continuous = continuous;     if(this.continuous)         clip.loop(-1);     else         clip.loop(0); }  public void play() {     second = !second;     if(!second)         return;     stopped = false;     try {         clip.stop();         clip.close();         initialize(file);         clip.open(stream);         clip.start();     }     catch(lineunavailableexception e) {         e.printstacktrace();     }     catch(ioexception e) {         e.printstacktrace();     }     stopwatch watch = new stopwatch();     watch.start();     while(!stopped) ;     clip.stop(); }  public void stop() {     stopped = true; }  public void run() {     play(); }  public double getplayfrequency() {     return playfrequency; }  public void setplayfrequency(double playfrequency) {     this.playfrequency = playfrequency; }  public boolean isstopped() {     return stopped; }  public soundfile clone() {     soundfile clone = new soundfile(getfile());     clone.setcontiuous(continuous);     clone.setplayfrequency(playfrequency);     clone.setvolume(volume);     return clone; }  public file getfile() {     return file; }  public sound.soundtype getsoundtype() {     return sound.soundtype.soundfile; }  public boolean issoundfile() {     return true; }  public volatile object clone()     throws clonenotsupportedexception {     return clone(); }  boolean stopped; boolean continuous; floatcontrol gaincontrol; clip clip; audioinputstream stream; double playfrequency; file file; double volume; boolean second; } 

the issue having whenever go next item (audio file) in menu, previous audio file doesn't stop (i need stop!). literally have no idea how fix cannot edit files inside jar. have uploaded of files here: https://drive.google.com/file/d/0bz9a-abbn69hsg1yrjfrwfnxqxc/view?usp=sharing

so can see i'm talking about.

-

key information:

in order run main program, need to:

  • run file named "menudriver_spt"

to navigate menu system within application:

  • on mac - hold down option , press space bar

  • on windows - hold down alt , press space bar

you navigate menu using arrow keys

if import file system eclipse, should run without problems. again files here: https://drive.google.com/file/d/0bz9a-abbn69hsg1yrjfrwfnxqxc/view?usp=sharing


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -