Ejemplo n.º 1
0
        /// <summary>
        /// 添加檔案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "音檔格式(*.mp3,*.wav)|*.mp3;*.wav";
            dlg.Multiselect = true;
            if (dlg.ShowDialog() != true)
            {
                return;
            }

            for (int i = 0; i < dlg.FileNames.Length; ++i)
            {
                finfo  newfile   = new finfo(dlg.SafeFileNames[i], dlg.FileNames[i]);
                string filelyric = dlg.FileNames[i].Remove(dlg.FileNames[i].Length - 4) + ".lrc";
                if (File.Exists(filelyric))
                {
                    ReadLyric(ref newfile, filelyric);
                }
                list.Add(newfile);
            }

            lb_list.SelectedIndex = (list.Count - 1);

            if (v_IsPause)
            {
                // 設置播放檔案
                SetSource();
            }
        }
Ejemplo n.º 2
0
        // 讀取歌詞
        private void ReadLyric(ref finfo f, string filelyric)
        {
            // 簡繁字體GB2312
            string lrc = File.ReadAllText(filelyric, System.Text.Encoding.GetEncoding("GB2312"));
            Regex  rx  = new Regex(@"(?<=^\[)(\d+:\d+\.\d+).(.+)(?=$)", RegexOptions.Multiline);

            //
            foreach (Match x in rx.Matches(lrc))
            {
                try
                {
                    TimeSpan ti = new TimeSpan(0, int.Parse(x.Value.Substring(0, 2)),
                                               int.Parse(x.Value.Substring(3, 2)));//int.Parse(x.Value.Substring(6, 2))
                }
                catch
                {
                    //continue;
                }
            }
        }