如何停止播放中断

嗨,我试图编辑此代码,但不知道从哪里开始。 我不是程序员,它是我尝试改造的传统游戏的公共源代码。 你能建议至少我需要看的地方,以便我可以阅读吗? 我想要达到的是:

现在的情况:

当从文件夹(由PATH或RAND指定)播放音乐,然后输入FILE命令指定要播放的另一个声音文件时,立即播放切换到新的声音文件,但继续循环播放该声音文件

期望的情况:

FILE命令切换到播放一次的新声音文件,然后将PATH重置为FILE命令之前的路径,即原始音乐恢复

我有一个有很多音乐的文件夹,我想像电台一样播放,但是当某个事件发生时,我想要播放另一个声音文件,然后返回到电台

这是用Java 1.3编写的,解决方案需要与jdk1.3.1_20进行编译。 让我知道你是否需要更多信息?

即使只是一个暗示,这是不可能的或困难的会很好。 提前致谢!

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/64451.html

上一篇: how to stop play interrupt

下一篇: Play framework/Netty does not release socket