Esempio n. 1
0
        private void buttonModifyLyric_Click(object sender, EventArgs e)
        {
            //得到要修改的txt文件,显示在textBox中
            if (listViewUserMusicList.Items.Count <= 0 || listViewUserMusicList.SelectedIndices.Count == 0 || listViewUserMusicList.SelectedIndices[0] < 0)
            {
                return;
            }

            //得到选中的音乐的名字,并显示在文本框中供修改
            FormLyric formLyric = new FormLyric();

            formLyric.Text = "修改歌词后,按[保存]键确认";
            string strTxtFilePath = listViewUserMusicList.SelectedItems[0].Tag.ToString().Substring(0, listViewUserMusicList.SelectedItems[0].Tag.ToString().Length - 3) + "txt";

            formLyric.Lyric = MusicHelper.GetLyricsByLyricFilePath(strTxtFilePath);
            if (formLyric.ShowDialog() == DialogResult.OK)
            {
                if (formLyric.Lyric != "")
                {
                    MusicHelper.SetLyricsByLyricFilePath(strTxtFilePath, formLyric.Lyric);
                }
            }

            formLyric.Dispose();
        }
Esempio n. 2
0
        private void listViewMusicList_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //显示音乐歌词内容
                if (listViewMusicList.SelectedIndices.Count > 0)
                {
                    //停止正在播放的歌曲
                    this.axWindowsMediaPlayer1.Ctlcontrols.stop();

                    textBoxLyric.Text = "";


                    //将目录和文件名拼接起来,找到文件,并打开、显示
                    string strLyricFilePath = "";
                    strLyricFilePath = listViewMusicList.Items[listViewMusicList.SelectedIndices[0]].Tag.ToString();
                    strLyricFilePath = strLyricFilePath.Remove(strLyricFilePath.Length - 4);
                    strLyricFilePath = strLyricFilePath + ".txt";

                    //显示歌词
                    StrTitle      = "";
                    StrLyric      = "";
                    StrPageNumber = "";


                    //如果[忽略换行],则去除换行符

                    StrLyric = MusicHelper.GetLyricsByLyricFilePath(strLyricFilePath).Trim();

                    StrTitle = listViewMusicList.Items[listViewMusicList.SelectedIndices[0]].Text;
                    //如果前n位为阿拉伯数字,则移除前n位

                    int iNumCount = 0;
                    for (int i = 0; i < StrTitle.Length; i++)
                    {
                        if (IsNumeric(StrTitle[i].ToString()))
                        {
                            iNumCount++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    StrTitle = StrTitle.Substring(iNumCount);

                    textBoxLyric.Text = StrLyric;


                    //逐行去除行前空格和行后空格,并将换行符替换为空格

                    string[] strsLyric = StrLyric.Replace("\r\n", "\\").Split('\\');

                    StrLyric = "";

                    for (int iRowNum = 0; iRowNum < strsLyric.Length; iRowNum++)
                    {
                        strsLyric[iRowNum] = strsLyric[iRowNum].Trim();

                        StrLyric += strsLyric[iRowNum];

                        if (iRowNum != strsLyric.Length - 1)
                        {
                            //如果忽略换行,则用空格连接
                            if (Settings.Default.IsIgnoreReturn)
                            {
                                //StrLyric += " ";
                            }
                            else
                            {
                                StrLyric += "\r\n";
                            }
                        }
                    }


                    //播放音乐
                    //音频文件,自动匹配mp3,wma,mid格式
                    string strAudioFilePath = "";
                    strAudioFilePath = listViewMusicList.Items[listViewMusicList.SelectedIndices[0]].Tag.ToString();

                    axWindowsMediaPlayer1.currentPlaylist.clear();

                    axWindowsMediaPlayer1.currentPlaylist.appendItem(axWindowsMediaPlayer1.newMedia(listViewMusicList.Items[listViewMusicList.SelectedIndices[0]].Tag.ToString()));

                    //this.axWindowsMediaPlayer1.Ctlcontrols.playItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(listViewMusicList.SelectedIndices[0]));

                    if (!listViewMusicList.Items[listViewMusicList.SelectedIndices[0]].Tag.ToString().EndsWith(".txt"))
                    {
                        this.axWindowsMediaPlayer1.Ctlcontrols.playItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(0));
                    }

                    DrawLyric();


                    //_formScreen.BIsNeedReCalculatePosition = true;

                    ////强制重绘
                    //_formScreen.Invalidate(true);
                    //
                    //MessageBox.Show(this.axWindowsMediaPlayer1.currentMedia.name);
                }
            }
            catch (Exception)
            {
            }
        }