[ti:真心英雄]
[ar:成龙]
[al:1]
[by:w]
[00:00.00][00:08.22]周华健、成龙、黄耀明、李宗盛演唱
[00:09.08]李宗盛词曲
[01:53.46][00:10.07][01:55.54][00:11.60]周:在我心中曾经有一个梦
[02:00.11][00:17.34]要用歌声让你忘了所有的痛
[02:05.68][00:21.29]成:灿烂星空谁是真的英雄
[02:10.49][00:27.87]平凡的人们给我最多感动
[02:15.50][00:32.20]黄:再没有恨也没有了痛
[02:20.91][00:37.88]但愿人间处处都有爱的影踪
[02:26.07][00:41.89]李:用我们的歌换你真心笑容
[02:31.23][00:48.23]合:祝福你的人生从此与众不同
[02:35.69][00:52.74][03:18.02][02:36.61][00:53.96]把握生命里的每一分钟
[03:22.81][02:41.27][00:58.68]全力以赴我们心中的梦
[03:27.96][02:46.10][01:03.30]不经历风雨怎么见彩虹
[03:33.09][02:51.98][01:09.05]没有人能随随便便成功
[03:37.84][02:56.25][01:12.94][03:38.44][02:57.03][01:14.54]把握生命里每一次感动
[03:43.17][03:01.84][01:18.87]和心爱的朋友热情相拥
[03:48.41][03:07.48][01:23.90]让真心的话和开心的泪
[03:53.73][03:12.05][01:29.70]在你我的心里流动
[03:58.31][01:33.65][03:59.46]LaLaLaLa.........
[04:18.84]把握生命里每一次感动
[04:23.97]和心爱的朋友热情相拥
[04:29.66]让真心的话和开心的泪
[04:34.64]在你我的心里流动
[04:39.98]让真心的话和开心的泪
[04:44.99]在你我的心里流动.
[04:48.86]
[04:49.70]
[04:50.38]
[01:36.2]
- package week3.exam6;
-
- //从文件导入数据,以Map 方式 TreeMap 保存 毫秒数做key,歌词做value
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.util.*;
-
- public class Play_Lyric {
- private static long n = -100;//开始歌词前就立即显示的时间给设置为负值
-
- private static long calSeconds(String str) {
- long minute;
- double second;
- String[] arrStr = str.split(":");
- minute = Long.parseLong(arrStr[0]);
- second = Double.parseDouble(arrStr[1]);
- return (long) ((minute * 60 + second) * 1000);
- }
-
- private static String longToStr(Long num) {
- long minute;
- double second;
- minute = num / 1000 / 60;
- second = (double) (num % 60000) / 1000;
- return "[" + String.format("%1$02d", minute) + ":" + String.format("%1$02d.%2$02d", (int) second, (int) (second - (int) second) * 100) + "]";
- }
-
- public static Map
lyricSplit(String str) {//解析一行歌词 - Map
map = new HashMap<>(); - if (Character.isAlphabetic(str.charAt(1))) {//第2个字符是字母的处理
- map.put(n++, str.substring(str.indexOf(":") + 1, str.length() - 1));
- } else {
- //正规条件的歌词
- String[] strArr = str.split("]");
- int length = strArr.length - 1;// 使用split()方法将字符串str按照"]"进行拆分,得到一个字符串数组strArr。数组的长度减1得到变量length,表示有几个显示点。
- String lyric = strArr[length];//从strArr数组中获取最后一个元素,即歌词内容,赋值给变量lyric
- Lyric[] lyrics = new Lyric[length];//建一个长度为length的Lyric对象数组lyrics
- for (int i = 0; i < length; i++) {
- strArr[i] = strArr[i].substring(1);
- lyrics[i] = new Lyric(lyric, strArr[i]);
- map.put(calSeconds(strArr[i]), lyric);
- }
- }
- return map;
- }
-
- public static void showLyric(TreeMap
map) { - long start = System.currentTimeMillis();//首先获取当前时间的毫秒数,并将其赋值给变量start作为起始时间
- System.out.println(" ~~~~~~~~~~~~~~~~~~~~~~歌词信息~~~~~~~~~~~~~~~~~~~~~~~~~");
-
- //将map转为list
-
- //先map转为Set
- Set
> entrySet = map.entrySet(); - //Set转为 list
- List
> entryList = new ArrayList<>(entrySet); -
- int i = 0;//追踪歌词展现的位置
- while (entryList.get(i).getKey() < 0) {
- System.out.println(entryList.get(i++).getValue());
- }
-
- while (i < entrySet.size()) {
-
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- long current = System.currentTimeMillis() - start;//计算当前时间与起始时间的差值,并将其赋值给变量current,表示已经过去的时间
- if (current > entryList.get(i).getKey()) {//如果current大于当前歌词对象的时间,说明该歌词应该被展示
- String lyric = longToStr(entryList.get(i).getKey()) + " " + entryList.get(i).getValue();//将当前歌词对象转换为字符串,并将其赋值给变量lyric
- System.out.println(lyric);
- i++;
-
- }
- }
- System.out.println("播放结束了~~~!");
- }
-
-
- public static void main(String[] args) {
- TreeMap
map = new TreeMap<>(); -
- File file = new File("hero.lrc");
- try {
- FileInputStream fis = new FileInputStream(file);
- Scanner sc = new Scanner(fis);
- while (sc.hasNext()) {
- String str = sc.nextLine();
- map.putAll(lyricSplit(str));
- }
- sc.close();
- showLyric(map);
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
- }