文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Lrc歌词解析器0.0.3.0

Lrc歌词解析器0.0.3.0

时间:2010-08-12  来源:mysiyer

1. 类图
 
2. 源码清单
package src.cn.edu.ynu.sei.livaPlayer.lrcAnalyst;

/**
 * 文件名:LrcScrollFrame.java
 * 环境: GNU/Linux Ubuntu 7.04 + Eclipse 3.2 + JDK 1.6
 * 功能:滚动的Lrc歌词显示面板
 * 版本:0.0.3.0
 * 版本改动:
 *     1. 简化了LivaPlayer 0.0.2.0版本中关于歌词显示的代码
 *     2. 修复了开始不能显示歌词的Bug
 * 作者:88250
 * 日期:2007.4.28
 * E-mail & MDN: [email protected]
 * QQ:845765
 *
 * Copyright (C) 2007 88250 <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.Date;


public class LrcScrollFrame extends JFrame
{
    /**
     * 歌词滚动面板构造器
     * @param lrcFileName 歌词文件路径和文件名
     */
    public LrcScrollFrame(String lrcFileName)
    {
    super(lrcFileName);
    ScrollPane textContentPane = new ScrollPane(lrcFileName);
    setBounds(600, 300, 370, 400);
    setResizable(false);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel pane = new JPanel();
    pane.setLayout(new GridLayout(1, 1, 0, 0));
    pane.add(textContentPane);
    setContentPane(pane);
    setVisible(true);
    }

}

/**
 * 歌词显示面板
 */
class ScrollPane extends JPanel implements Runnable
{

    /**
     * 参考纵坐标,控制动画效果
     */
    private static int y;
   
    private static long sleepTime = 0;
    private long startTime = 0;

    /**
     * @see src.cn.edu.ynu.sei.livaPlayer.lrcAnalyst.LrcAnalystBase
     */
    private LrcAnalystBase lrcAnalystBase = new LrcAnalystBase();
   
    /**
         * 默认的构造器,创建一个新的线程并直接开启它
         *
         * @param lrcFileName
         *                歌词文件路径和文件名
         * @see src.cn.edu.ynu.sei.livaPlayer.lrcAnalyst.ScrollPane.run()
         *    
         */
    public ScrollPane(String lrcFileName)
    {
    // 读歌词文件
    lrcAnalystBase.readFile(lrcFileName);
    // 解析歌词文件
    lrcAnalystBase.parseLyrics();
   
    Date startDate = new Date();
    startTime = startDate.getTime();
   
    new Thread(this).start();
    }

    /**
         * 在线程的run里面,它每次都会使y改变,然后调用repaint()方法,此方法会调用paint再画一次
         * 再画一次的时候,里面的y坐标是每次都会变的,这样就形成了一种动画效果
         * @see src.cn.edu.ynu.sei.livaPlayer.lrcAnalyst.LrcTimeAndIndex<br>
         * 这个类表述了如何让歌词显示时间和歌词内容进行对应
         *
         */
    public void run()
    {
    while (true)
    {
        y--;
       
        long currentTime = new Date().getTime();
        LrcTimeAndIndex lrcTimeAndIndex = new LrcTimeAndIndex();

        // 注意:在这里,歌词同步有问题,将在下一个版本中得到修正
        sleepTime = currentTime - startTime
            - (long) lrcTimeAndIndex.getLrcTime();
       
        try
        {
        Thread.sleep(sleepTime);
        }
        catch (InterruptedException e)
        {
        e.printStackTrace();
        }
       
        repaint();
    }
    }

    public void paint(Graphics g)
    {
    Graphics2D g2D = (Graphics2D) g;
    Font type = new Font("monospaced", Font.BOLD, 14);
    g2D.setFont(type);
    g2D.setColor(Color.black);
    g2D.fillRect(0, 0, getSize().width, getSize().height);
    g2D.setColor(Color.blue);
   
    for (int i = 0; i < lrcAnalystBase.getLrcContent().size(); i++)
    {
        g2D.drawString((String) lrcAnalystBase.getLrcContent().get(i), 5, y + (20 * i));
    }
    }
}

3. 工程文件
    工程文件就不贴了,因为还要有改动。下一个版本中因为显示效率问题,所以显示歌词部分不准备用Draw的  方式了,可能会用JDK自带的JScrollPane结合JScrollBar的方式。请大家见谅!


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/DL88250/archive/2007/05/04/1596191.aspx

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载