⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lyric.java

📁 YOYOPlayer MP3播放器 java+JMF实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            case Config.LYRIC_CENTER_ALIGN:                x = (width - sen.getContentWidth(g)) / 2;                break;            case Config.LYRIC_LEFT_ALIGN:                x = 0;                break;            case Config.LYRIC_RIGHT_ALIGN:                x = width - sen.getContentWidth(g);                break;            default://默认情况还是中间对齐                x = (width - sen.getContentWidth(g)) / 2;                break;        }        return x;    }    /**     * 画出自己在垂直方向上的过程     * @param g 画笔     */    public synchronized void drawV(Graphics g) {        if (!enabled) {            Sentence sen = new Sentence(info.getFormattedName());            int x = (width - sen.getContentWidth(g)) / 2;            int y = (height - sen.getContentHeight(g) + Config.getConfig().getV_SPACE()) / 2;            g.setColor(Config.getConfig().getLyricHilight());            Util.drawString(g, sen.getContent(), x, y);            return;        }        //首先看是不是初始化完毕了        if (!initDone) {            Sentence temp = new Sentence("正在搜索歌词");            int x = getSentenceX(g, temp);            int y = (height - temp.getContentHeight(g)) / 2;            g.setColor(Config.getConfig().getLyricHilight());            Util.drawString(g, temp.getContent(), x, y);            return;        }        //如果只存在一句的话,那就不要浪费那么多计算的时候了        //直接画在中间就可以了        if (list.size() == 1) {            Sentence sen = list.get(0);            int x = getSentenceX(g, sen);            int y = (height - sen.getContentHeight(g)) / 2;            g.setColor(Config.getConfig().getLyricHilight());            Util.drawString(g, sen.getContent(), x, y);        } else {            long t = tempTime;            Graphics2D gd = (Graphics2D) g;            int index = getNowSentenceIndex(t);            if (!isMoving) {                currentIndex = index;            }            if (index == -1) {                Sentence sen = new Sentence(info.getFormattedName(), Integer.MIN_VALUE, Integer.MAX_VALUE);                int x = getSentenceX(g, sen);                int y = (height - sen.getContentHeight(g)) / 2;                gd.setPaint(Config.getConfig().getLyricHilight());                Util.drawString(g, sen.getContent(), x, y);                return;            }            Sentence now = list.get(index);            //先求出中间的最基准的纵座标            int y = (height + now.getContentHeight(g)) / 2 - now.getVIncrease(g, t);            int x = getSentenceX(g, now);            this.drawKaraoke(gd, now, x, y, t);            gd.setColor(Config.getConfig().getLyricForeground());            //然后再画上面的部份以及下面的部份            //这样就可以保证正在唱的歌词永远在正中间显示            int tempY = y;            //画出本句之前的句子            for (int i = index - 1; i >= 0; i--) {                Sentence sen = list.get(i);                int x1 = getSentenceX(g, sen);                tempY = tempY - sen.getContentHeight(g) - Config.getConfig().getV_SPACE();                if (tempY + sen.getContentHeight(g) < 0) {                    break;                }                if (Config.getConfig().isLyricShadow()) {                    if (i == index - 1) {                        gd.setColor(sen.getBestOutColor(Config.getConfig().getLyricHilight(),                                Config.getConfig().getLyricForeground(), time));                    } else {                        gd.setColor(Config.getConfig().getLyricForeground());                    }                }                Util.drawString(g, sen.getContent(), x1, tempY);            }            gd.setColor(Config.getConfig().getLyricForeground());            tempY = y;            //画出本句之后的句子             for (int i = index + 1; i < list.size(); i++) {                Sentence sen = list.get(i);                int x1 = getSentenceX(g, sen);                tempY = tempY + sen.getContentHeight(g) + Config.getConfig().getV_SPACE();                if (tempY > height) {                    break;                }                Util.drawString(g, sen.getContent(), x1, tempY);            }        }    }    /**     * 得到当前正在播放的那一句的下标     * 不可能找不到,因为最开头要加一句     * 自己的句子 ,所以加了以后就不可能找不到了     * @return 下标     */    private int getNowSentenceIndex(long t) {        for (int i = 0; i < list.size(); i++) {            if (list.get(i).isInTime(t)) {                return i;            }        }//        throw new RuntimeException("竟然出现了找不到的情况!");        return -1;    }    /**     * 水平移动多少个象素,这个方法是给面板调用的     * 移动了这些象素以后,要马上算出这个象素所     * 对应的时间是多少,要注意时间超出的情况     * @param length     * @param g 画笔,因为对于每一个画笔长度不一样的     */    public void moveH(int length, Graphics g) {        if (list.size() == 1 || !enabled) {            return;        }        //如果长度是大于0的,则说明是正向移动,快进        if (length > 0) {            Sentence now = list.get(currentIndex);            int nowWidth = now.getContentWidth(g);            float f = (time - now.getFromTime()) * 1.0f / (now.getToTime() - now.getFromTime());            //先算出当前的这一句还剩多少长度了            int rest = (int) ((1 - f) * nowWidth);            long timeAdd = 0;//要加多少时间            //如果剩下的长度足够了,那是最好,马上就可以返回了            if (rest > length) {                timeAdd = now.getTimeH(length, g);            } else {                timeAdd = now.getTimeH(rest, g);                for (int i = currentIndex; i < list.size(); i++) {                    Sentence sen = list.get(i);                    int len = sen.getContentWidth(g);                    //如果加上下一句的长度还不够,就把时间再加,继续下一句                    if (len + rest < length) {                        timeAdd += sen.getDuring();                        rest += len;                    } else {                        timeAdd += sen.getTimeH(length - rest, g);                        break;                    }                }            }            tempTime = time + timeAdd;            checkTempTime();        } else {//否则就是反向移动,要快退了            length = 0 - length;//取它的正数            Sentence now = list.get(currentIndex);            int nowWidth = now.getContentWidth(g);            float f = (time - now.getFromTime()) * 1.0f / (now.getToTime() - now.getFromTime());            //先算出当前的这一句已经用了多少长度了            int rest = (int) (f * nowWidth);            long timeAdd = 0;//要加多少时间            //如果剩下的长度足够了,那是最好,马上就可以返回了            if (rest > length) {                timeAdd = now.getTimeH(length, g);            } else {                timeAdd = now.getTimeH(rest, g);                for (int i = currentIndex; i > 0; i--) {                    Sentence sen = list.get(i);                    int len = sen.getContentWidth(g);                    //如果加上下一句的长度还不够,就把时间再加,继续下一句                    if (len + rest < length) {                        timeAdd += sen.getDuring();                        rest += len;                    } else {                        timeAdd += sen.getTimeH(length - rest, g);                        break;                    }                }            }            tempTime = time - timeAdd;            checkTempTime();        }    }    /**     * 竖直移动多少个象素,这个方法是给面板调用的     * 移动了这些象素以后,要马上算出这个象素所     * 对应的时间是多少,要注意时间超出的情况     * @param length     * @param g 画笔,因为对于每一个画笔长度不一样的     */    public void moveV(int length, Graphics g) {        if (list.size() == 1 || !enabled) {            return;        }        //如果长度是大于0的,则说明是正向移动,快进        if (length > 0) {            Sentence now = list.get(currentIndex);            int nowHeight = now.getContentHeight(g);            float f = (time - now.getFromTime()) * 1.0f / (now.getToTime() - now.getFromTime());            //先算出当前的这一句还剩多少长度了            int rest = (int) ((1 - f) * nowHeight);            long timeAdd = 0;//要加多少时间            //如果剩下的长度足够了,那是最好,马上就可以返回了            if (rest > length) {                timeAdd = now.getTimeV(length, g);            } else {                timeAdd = now.getTimeV(rest, g);                for (int i = currentIndex; i < list.size(); i++) {                    Sentence sen = list.get(i);                    int len = sen.getContentHeight(g);                    //如果加上下一句的长度还不够,就把时间再加,继续下一句                    if (len + rest < length) {                        timeAdd += sen.getDuring();                        rest += len;                    } else {                        timeAdd += sen.getTimeV(length - rest, g);                        break;                    }                }            }            tempTime = time + timeAdd;            checkTempTime();        } else {//否则就是反向移动,要快退了            length = 0 - length;//取它的正数            Sentence now = list.get(currentIndex);            int nowHeight = now.getContentHeight(g);            float f = (time - now.getFromTime()) * 1.0f / (now.getToTime() - now.getFromTime());            //先算出当前的这一句已经用了多少长度了            int rest = (int) (f * nowHeight);            long timeAdd = 0;//要加多少时间            //如果剩下的长度足够了,那是最好,马上就可以返回了            if (rest > length) {                timeAdd = now.getTimeV(length, g);            } else {                timeAdd = now.getTimeV(rest, g);                for (int i = currentIndex; i > 0; i--) {                    Sentence sen = list.get(i);                    int len = sen.getContentHeight(g);                    //如果加上下一句的长度还不够,就把时间再加,继续下一句                    if (len + rest < length) {                        timeAdd += sen.getDuring();                        rest += len;                    } else {                        timeAdd += sen.getTimeV(length - rest, g);                        break;                    }                }            }            tempTime = time - timeAdd;            checkTempTime();        }    }    /**     * 是否能拖动,只有有歌词才可以被拖动,否则没有意义了     * @return 能否拖动     */    public boolean canMove() {        return list.size() > 1 && enabled;    }    /**     * 得到当前的时间,一般是由显示面板调用的     */    public long getTime() {        return tempTime;    }    /**     * 在对tempTime做了改变之后,检查一下它的     * 值,看是不是在有效的范围之内     */    private void checkTempTime() {        if (tempTime < 0) {            tempTime = 0;        } else if (tempTime > during) {            tempTime = during;        }    }    /**     * 告诉歌词,要开始移动了,     * 在此期间,所有对歌词的直接的时间设置都不理会     */    public void startMove() {        isMoving = true;    }    /**     * 告诉歌词拖动完了,这个时候的时间改     * 变要理会,并做更改     */    public void stopMove() {        isMoving = false;    }    public static void main(String[] args) {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -