how to stop play interrupt
Hi I am trying to edit this code but don't know where to start. I'm not a programmer and it's public source code from a legacy game I am trying to mod. Can you suggest at least the area I need to look in so I can read up? What I want to achieve is:
Current situation:
When music is playing from a folder (specified by PATH or RAND) and then FILE command is entered to specify another sound file to play, play immediately switches to the new sound file but then continues to loop play that soundfile
Desired situation:
FILE command switches to new soundfile that plays once, then PATH is reset to the path previous to the FILE command ie the original music resumes
I have a folder with lots of music that I want to play like a radio station, but when a certain event happens I want another sound file to play, then return to the radio station afterwards
This was written in Java 1.3 and the solution needs to be compilable with jdk1.3.1_20. Let me know if you need any more info?
Even just a hint that it's impossible or difficult would be great. Thanks in advance!
public class CmdMusic extends Cmd { static class PlayInfo { public String objName; public boolean isPath; public String list[]; public PlayInfo(String s, boolean flag) { objName = s; isPath = flag; list = null; } public PlayInfo(String as[]) { objName = null; isPath = false; list = as; } } static class WFileFilter implements FileFilter { public boolean accept(File file) { if(!file.isFile() || file.isHidden()) return false; String s = file.getName(); if(s == null) return false; int i = s.length(); if(i faderIncr) { fader -= faderIncr; prevMusic.setVolume(fader); } else { prevMusic.cancel(); prevMusic.release(); prevMusic = null; } if(list != null) { if(curMusic != null && !curMusic.isPlaying() && playState()) { curMusic.cancel(); curMusic.release(); curMusic = null; } if(curMusic == null && playState()) { index++; if(index >= list.length) index = 0; fileName = null; setFile(list[index], true); } } } public static boolean isPathEnabled(String s) { byte byte0 = -1; if(s == null) return true; if(s.compareToIgnoreCase("music/takeoff") == 0) byte0 = 0; else if(s.compareToIgnoreCase("music/inflight") == 0) byte0 = 1; else if(s.compareToIgnoreCase("music/crash") == 0) byte0 = 2; else return true; SoundFlags soundflags = (SoundFlags)CfgTools.get("MusState"); if(soundflags == null) return false; else return soundflags.get(byte0); } public static void setPath(String s, boolean flag) { if(s == null) return; if(flag && pathRandName != null && s.compareToIgnoreCase(pathRandName) == 0) return; File file = new File("./samples/" + s); File afile[] = file.listFiles(new WFileFilter()); if(afile == null || afile.length 1.0F) System.out.println("ERROR: value must be between 0.0 - 1.0"); else setVolume(f); } } } return CmdEnv.RETURN_OK; } private static final boolean _debug = false; protected static SoundFX musFX = null; protected static String fileName = null; protected static String pathRandName = null; protected static float vol = 1.0F; protected static Random rnd = new Random(); protected static Stack stack = new Stack(); protected static boolean bPlay = false; protected static boolean bPlaying = false; protected static boolean bList = false; public static final String PATH = "PATH"; public static final String RAND = "RAND"; public static final String FILE = "FILE"; public static final String LIST = "LIST"; public static final String PLAY = "PLAY"; public static final String STOP = "STOP"; public static final String BREAK = "BREAK"; public static final String VOL = "VOL"; public static final String PUSH = "PUSH"; public static final String POP = "POP"; public static final String APPLY = "APPLY"; private static AudioStream prevMusic = null; private static AudioStream curMusic = null; private static float faderIncr = 0.02F; private static float fader = 1.0F; private static String list[] = null; private static int index = 0; }链接地址: http://www.djcxy.com/p/64452.html
上一篇: java线程无限循环,套接字编程
下一篇: 如何停止播放中断