zoukankan      html  css  js  c++  java
  • 0505.Net基础班第二十一天(基础加强总复习)

    1、取消播放器的自动播放功能 2、播放或者暂停按钮 3、下一曲、上一曲 4、多选删除 5、静音和放音 6、选择列表中的音乐文件,单击播放按钮直接播放 7、自动进行下一曲

    15秒  44秒 当我和世界不一样 44.--47 那就让我不一样

       lblInfomation.Text = musicPlayer.currentMedia.duration.ToString() + " " + musicPlayer.currentMedia.durationString + " " + musicPlayer.Ctlcontrols.currentPosition.ToString() + " " + musicPlayer.Ctlcontrols.currentPositionString;

    01Path类复习

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.IO;
     7 
     8 namespace _01Path类复习
     9 {
    10     class Program
    11     {
    12         static void Main(string[] args)
    13         {
    14             string path = @"C:UsersSpringRainDesktop505.Net基础班第二十一天.txt";
    15             Console.WriteLine(Path.GetDirectoryName(path));
    16             //Console.WriteLine(Path.ChangeExtension(path, "jpg"));
    17             Console.ReadKey();
    18         }
    19     }
    20 }
    View Code

    02File类

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.IO;
     7 namespace _02File类
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             //操作文件的
    14             //复制、剪切、创建、移除
    15 
    16 
    17             //File.Create(@"C:UsersSpringRainDesktop
    ew.txt");
    18             //Console.WriteLine("创建成功");
    19 
    20             //File.Delete(@"C:UsersSpringRainDesktop
    ew.txt");
    21             //Console.WriteLine("删除成功");
    22 
    23             //File.Move(@"C:UsersSpringRainDesktop505.Net基础班第二十一天.txt", @"C:UsersSpringRainDesktop1.txt");
    24             //Console.ReadKey();
    25 
    26 
    27             //使用File类来读取数据
    28 
    29 
    30             //byte[] buffer = File.ReadAllBytes(@"C:UsersSpringRainDesktop1.txt");
    31 
    32             //string str = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
    33 
    34             //Console.WriteLine(str);
    35 
    36             ////编码:把字符串以怎样形式存储为二进制  ASCII  GBK  GB2312   UTF-8  
    37             //Console.ReadKey();
    38 
    39             //string[] str = File.ReadAllLines(@"C:UsersSpringRainDesktop1.txt",Encoding.Default);
    40 
    41             //for (int i = 0; i < str.Length; i++)
    42             //{
    43             //    Console.WriteLine(str[i]);
    44             //}
    45 
    46 
    47             //string str = File.ReadAllText(@"C:UsersSpringRainDesktop1.txt",Encoding.Default);
    48             //Console.WriteLine(str);
    49             //Console.ReadKey();
    50 
    51 
    52 
    53 
    54             //===============================================File类写入
    55             //string str="哈哈";
    56 
    57             //byte[] buffer=Encoding.Default.GetBytes(str);
    58 
    59             //File.WriteAllBytes(@"C:UsersSpringRainDesktop
    ew.txt", buffer);
    60             //Console.WriteLine("OK");
    61 
    62 
    63             //File.WriteAllLines(@"C:UsersSpringRainDesktop1.txt", new string[] { "张三", "李四", "王五", "赵六" });
    64             //Console.WriteLine("OK");
    65 
    66 
    67            // File.WriteAllText(@"C:UsersSpringRainDesktop1.txt", "今天还是比较凉快的");
    68 
    69 
    70             //File.AppendAllText(@"C:UsersSpringRainDesktop1.txt", "没有覆盖哟");
    71             //Console.WriteLine("OK");
    72             //Console.ReadKey();
    73 
    74 
    75         }
    76     }
    77 }
    View Code

    03Directory

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.IO;
     7 namespace _03Directory
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             //Directory.CreateDirectory(@"C:UsersSpringRainDesktop新建文件夹");
    14             //Console.WriteLine("OK");
    15 
    16 
    17             //Directory.Delete(@"C:UsersSpringRainDesktop新建文件夹",true);
    18             //Console.ReadKey();
    19 
    20             //Directory.Move(@"C:UsersSpringRainDesktopMusic", @"C:UsersSpringRainDesktopNewMusic");
    21             //Console.WriteLine("OK");
    22             //Console.ReadKey();
    23 
    24 
    25             //string[] path = Directory.GetFiles(@"C:UsersSpringRainDesktopNewMusic","*.lrc");
    26             //for (int i = 0; i < path.Length; i++)
    27             //{
    28             //    Console.WriteLine(path[i]);
    29             //}
    30             //Console.ReadKey();
    31         }
    32     }
    33 }
    View Code

    04文件类练习

     1 using System;
     2 using System.Collections.Generic;
     3 using System.IO;
     4 using System.Linq;
     5 using System.Text;
     6 using System.Threading.Tasks;
     7 
     8 namespace _04文件类练习
     9 {
    10     class Program
    11     {
    12         static void Main(string[] args)
    13         {
    14             //案例:对职工工资文件处理,所有人的工资加倍然后输出到新文件。
    15             //文件案例:
    16             //马大哈|3000
    17             //宋江|8000
    18 
    19             string[] str = File.ReadAllLines(@"C:UsersSpringRainDesktop工资1.txt", Encoding.UTF8);
    20             for (int i = 0; i < str.Length; i++)
    21             {
    22                 //张三|5000
    23                 string[] strNew = str[i].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
    24                 //张三  5000
    25                 //int salary = int.Parse(strNew[1]) * 2;
    26                 strNew[1] = (int.Parse(strNew[1]) * 2).ToString();
    27                 //10000
    28                 File.AppendAllLines(@"C:UsersSpringRainDesktop工资1.txt", strNew,Encoding.UTF8);
    29              //   str[i] = strNew[0] + salary.ToString();
    30               //  File.WriteAllLines();
    31             }
    32 
    33          //   File.WriteAllLines(@"C:UsersSpringRainDesktop工资.txt", str);
    34             Console.WriteLine("Ok");
    35             Console.ReadKey();
    36         }
    37     }
    38 }
    View Code

    05文件流复习

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 using System.IO;
     7 namespace _05文件流复习
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             //  FileStream StreamReader StreamWriter
    14             //using (FileStream fsRead = new FileStream(@"C:UsersSpringRainDesktop1.wmv", FileMode.OpenOrCreate, FileAccess.Read))
    15             //{
    16             //    byte[] buffer = new byte[fsRead.Length];
    17             //    //表示本次读取实际读取到的有效字节数
    18             //    int r = fsRead.Read(buffer, 0, buffer.Length);
    19 
    20             //    string s = Encoding.Default.GetString(buffer, 0,r);
    21             //    Console.WriteLine(s);
    22             //}
    23 
    24             //using (FileStream fsWrite = new FileStream(@"C:UsersSpringRainDesktop1.txt", FileMode.Append, FileAccess.Write))
    25             //{ 
    26             //    string s="今天天气好晴朗";
    27             //    byte[] buffer=Encoding.Default.GetBytes(s);
    28             //    fsWrite.Write(buffer, 0, buffer.Length);
    29             //}
    30             //Console.WriteLine("写入成功");
    31 
    32             //Console.ReadKey();
    33 
    34             //using (FileStream fsRead = new FileStream(@"C:UsersSpringRainDesktop1.txt", FileMode.OpenOrCreate, FileAccess.Read))
    35             //{
    36             //    using (StreamReader sr = new StreamReader(fsRead,Encoding.Default))
    37             //    {
    38             //        while (!sr.EndOfStream)
    39             //        {
    40             //            Console.WriteLine(sr.ReadLine());
    41             //        }
    42             //    }
    43             //}
    44             //byte[] buffer = new byte[1024 * 1024];
    45             //using (StreamWriter sw = new StreamWriter(@"C:UsersSpringRainDesktop1.txt", true, Encoding.Default, buffer.Length))
    46             //{
    47             //    sw.WriteLine("哈哈哈");
    48             //}
    49             //Console.WriteLine("OK");
    50 
    51             //Console.ReadKey();
    52 
    53         }
    54 
    55     }
    56 }
    View Code

    06序列化

     1 using System;
     2 using System.Collections.Generic;
     3 using System.IO;
     4 using System.Linq;
     5 using System.Runtime.Serialization.Formatters.Binary;
     6 using System.Text;
     7 using System.Threading.Tasks;
     8 
     9 namespace _06序列化
    10 {
    11     class Program
    12     {
    13         static void Main(string[] args)
    14         {
    15             //要将序列化对象的类 标记为可以被序列化的
    16 
    17             //Person p = new Person();
    18             //p.Name = "张三";
    19             //p.Age = 10;
    20             //p.Gender = '男';
    21 
    22             //using (FileStream fsWrite = new FileStream(@"C:UsersSpringRainDesktop
    ew.txt", FileMode.OpenOrCreate, FileAccess.Write))
    23             //{
    24             //    BinaryFormatter bf = new BinaryFormatter();
    25             //    bf.Serialize(fsWrite, p);
    26             //}
    27             //Console.WriteLine("序列化成功");
    28 
    29             //Console.ReadKey();
    30 
    31             Person p;
    32             using (FileStream fsRead = new FileStream(@"C:UsersSpringRainDesktop
    ew.txt", FileMode.OpenOrCreate, FileAccess.Read))
    33             {
    34                 BinaryFormatter bf = new BinaryFormatter();
    35                 p = (Person)bf.Deserialize(fsRead);
    36             }
    37             Console.WriteLine(p.Name);
    38             Console.WriteLine(p.Age);
    39             Console.WriteLine(p.Gender);
    40             Console.ReadKey();
    41 
    42         }
    43     }
    44 
    45     [Serializable]
    46     public class Person
    47     {
    48         public string Name
    49         {
    50             get;
    51             set;
    52         }
    53 
    54         public int Age
    55         {
    56             get;
    57             set;
    58         }
    59         public char Gender
    60         {
    61             get;
    62             set;
    63         }
    64     }
    65 }
    View Code

    播放器项目

      1 using System;
      2 using System.Collections.Generic;
      3 using System.ComponentModel;
      4 using System.Data;
      5 using System.Drawing;
      6 using System.IO;
      7 using System.Linq;
      8 using System.Text;
      9 using System.Threading.Tasks;
     10 using System.Windows.Forms;
     11 
     12 namespace 播放器项目
     13 {
     14     public partial class Form1 : Form
     15     {
     16         public Form1()
     17         {
     18             InitializeComponent();
     19         }
     20 
     21         private void button1_Click(object sender, EventArgs e)
     22         {
     23             musicPlayer.Ctlcontrols.play();
     24         }
     25 
     26         private void button2_Click(object sender, EventArgs e)
     27         {
     28             musicPlayer.Ctlcontrols.pause();
     29         }
     30 
     31         private void button3_Click(object sender, EventArgs e)
     32         {
     33             musicPlayer.Ctlcontrols.stop();
     34         }
     35 
     36         private void Form1_Load(object sender, EventArgs e)
     37         {
     38             //在程序加载的时候 取消播放器的自动播放功能
     39             musicPlayer.settings.autoStart = false;
     40             // musicPlayer.URL = @"C:UsersSpringRainDesktopNewMusic倔强.mp3";
     41             //label1.Image = Image.FromFile(@"C:UsersSpringRainDesktop放音.jpg");
     42         }
     43         /// <summary>
     44         /// 播放或者暂停
     45         /// </summary>
     46         /// <param name="sender"></param>
     47         /// <param name="e"></param>
     48         /// 
     49         bool b = true;
     50         private void btnPlayorPause_Click(object sender, EventArgs e)
     51         {
     52             if (btnPlayorPause.Text == "播放")
     53             {
     54                 if (b)
     55                 {
     56                     //获得选中的歌曲  让音乐从头播放
     57                     musicPlayer.URL = listPath[listBox1.SelectedIndex];
     58                 }
     59                 musicPlayer.Ctlcontrols.play();
     60                 btnPlayorPause.Text = "暂停";
     61             }
     62             else if (btnPlayorPause.Text == "暂停")
     63             {
     64                 musicPlayer.Ctlcontrols.pause();
     65                 btnPlayorPause.Text = "播放";
     66                 b = false;
     67             }
     68         }
     69 
     70         private void button3_Click_1(object sender, EventArgs e)
     71         {
     72             musicPlayer.Ctlcontrols.stop();
     73         }
     74 
     75 
     76         //存储音乐文件的全路径
     77         List<string> listPath = new List<string>();
     78 
     79         /// <summary>
     80         /// 打开对话框 选择音乐
     81         /// </summary>
     82         /// <param name="sender"></param>
     83         /// <param name="e"></param>
     84         private void button4_Click(object sender, EventArgs e)
     85         {
     86             OpenFileDialog ofd = new OpenFileDialog();
     87             ofd.InitialDirectory = @"F:老赵生活music";
     88             ofd.Filter = "音乐文件|*.wav|MP3文件|*.mp3|所有文件|*.*";
     89             ofd.Title = "请选择音乐文件哟亲o(^▽^)o";
     90             ofd.Multiselect = true;
     91             ofd.ShowDialog();
     92 
     93             //获得在文本框中选择文件的全路径
     94             string[] path = ofd.FileNames;
     95             for (int i = 0; i < path.Length; i++)
     96             {
     97                 //将音乐文件的全路径存储到泛型集合中
     98                 listPath.Add(path[i]);
     99                 //将音乐文件的文件名存储到ListBox中
    100                 listBox1.Items.Add(Path.GetFileName(path[i]));
    101             }
    102         }
    103 
    104 
    105         /// <summary>
    106         /// 双击播放对应的音乐
    107         /// </summary>
    108         /// <param name="sender"></param>
    109         /// <param name="e"></param>
    110         private void listBox1_DoubleClick(object sender, EventArgs e)
    111         {
    112             if (listBox1.Items.Count == 0)
    113             {
    114                 MessageBox.Show("请首先选择音乐文件");
    115                 return;
    116             }
    117             try
    118             {
    119                 musicPlayer.URL = listPath[listBox1.SelectedIndex];
    120                 musicPlayer.Ctlcontrols.play();
    121                 btnPlayorPause.Text = "暂停";
    122                 // lblInformation.Text = musicPlayer.currentMedia.duration.ToString();
    123                 IsExistLrc(listPath[listBox1.SelectedIndex]);
    124 
    125             }
    126             catch { }
    127         }
    128 
    129 
    130         /// <summary>
    131         /// 点击下一曲
    132         /// </summary>
    133         /// <param name="sender"></param>
    134         /// <param name="e"></param>
    135         private void button6_Click(object sender, EventArgs e)
    136         {
    137             //获得当前选中项的索引
    138             int index = listBox1.SelectedIndex;
    139 
    140             //清空所有选中项的索引
    141             listBox1.SelectedIndices.Clear();
    142             index++;
    143             if (index == listBox1.Items.Count)
    144             {
    145                 index = 0;
    146             }
    147             //将改变后的索引重新的赋值给当前选中项的索引
    148             listBox1.SelectedIndex = index;
    149             musicPlayer.URL = listPath[index];
    150             musicPlayer.Ctlcontrols.play();
    151         }
    152 
    153 
    154         /// <summary>
    155         /// 点击上一曲
    156         /// </summary>
    157         /// <param name="sender"></param>
    158         /// <param name="e"></param>
    159         private void button5_Click(object sender, EventArgs e)
    160         {
    161             int index = listBox1.SelectedIndex;
    162             listBox1.SelectedIndices.Clear();
    163 
    164             index--;
    165             if (index < 0)
    166             {
    167                 index = listBox1.Items.Count - 1;
    168             }
    169             listBox1.SelectedIndex = index;
    170 
    171             musicPlayer.URL = listPath[index];
    172             musicPlayer.Ctlcontrols.play();
    173 
    174         }
    175 
    176 
    177         /// <summary>
    178         /// 点击删除 选中项
    179         /// </summary>
    180         /// <param name="sender"></param>
    181         /// <param name="e"></param>
    182         private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
    183         {
    184             //先删列表还是先删集合?
    185 
    186 
    187             //首先获得要删除的歌曲的数量
    188             int count = listBox1.SelectedItems.Count;
    189             for (int i = 0; i < count; i++)
    190             {
    191                 //先删集合
    192                 listPath.RemoveAt(listBox1.SelectedIndex);
    193                 //再删列表
    194                 listBox1.Items.RemoveAt(listBox1.SelectedIndex);
    195 
    196             }
    197 
    198         }
    199 
    200 
    201         /// <summary>
    202         /// 点击放音或者静音
    203         /// </summary>
    204         /// <param name="sender"></param>
    205         /// <param name="e"></param>
    206         private void label1_Click(object sender, EventArgs e)
    207         {
    208             if (label1.Tag.ToString() == "1")
    209             {
    210                 //目的:让你静音
    211                 musicPlayer.settings.mute = true;
    212                 //显示静音的图片
    213                 label1.Image = Image.FromFile(@"C:UsersSpringRainDesktop静音.jpg");
    214                 label1.Tag = "2";
    215 
    216             }
    217             else if (label1.Tag.ToString() == "2")
    218             {
    219                 //放音
    220                 musicPlayer.settings.mute = false;
    221                 //显示放音的图片
    222                 label1.Image = Image.FromFile(@"C:UsersSpringRainDesktop放音.jpg");
    223                 label1.Tag = "1";
    224             }
    225         }
    226 
    227 
    228         /// <summary>
    229         /// 放大音量
    230         /// </summary>
    231         /// <param name="sender"></param>
    232         /// <param name="e"></param>
    233         private void button7_Click(object sender, EventArgs e)
    234         {
    235             musicPlayer.settings.volume += 5;
    236             // MessageBox.Show(musicPlayer.settings.volume.ToString());
    237         }
    238 
    239 
    240         /// <summary>
    241         /// 减小声音
    242         /// </summary>
    243         /// <param name="sender"></param>
    244         /// <param name="e"></param>
    245         private void button8_Click(object sender, EventArgs e)
    246         {
    247             musicPlayer.settings.volume -= 5;
    248         }
    249 
    250         private void timer1_Tick(object sender, EventArgs e)
    251         {
    252             //如果播放器的状态等于正在播放中
    253 
    254             if (musicPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
    255             {
    256                 lblInformation.Text = musicPlayer.currentMedia.duration.ToString() + "
    " + musicPlayer.currentMedia.durationString + "
    " + musicPlayer.Ctlcontrols.currentPosition.ToString() + "
    " + musicPlayer.Ctlcontrols.currentPositionString;
    257             }
    258 
    259             #region 方法1
    260             //if (musicPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
    261             //{
    262             //    lblInformation.Text = musicPlayer.currentMedia.duration.ToString() + "
    " + musicPlayer.currentMedia.durationString + "
    " + musicPlayer.Ctlcontrols.currentPosition.ToString() + "
    " + musicPlayer.Ctlcontrols.currentPositionString;
    263 
    264             //    double d1 = double.Parse(musicPlayer.currentMedia.duration.ToString());
    265 
    266             //    double d2 = double.Parse(musicPlayer.Ctlcontrols.currentPosition.ToString()) + 1;
    267 
    268             //    if (d1 <= d2)
    269             //    {
    270             //        //获得当前选中项的索引
    271             //        int index = listBox1.SelectedIndex;
    272 
    273             //        //清空所有选中项的索引
    274             //        listBox1.SelectedIndices.Clear();
    275             //        index++;
    276             //        if (index == listBox1.Items.Count)
    277             //        {
    278             //            index = 0;
    279             //        }
    280             //        //将改变后的索引重新的赋值给当前选中项的索引
    281             //        listBox1.SelectedIndex = index;
    282             //        musicPlayer.URL = listPath[index];
    283             //        musicPlayer.Ctlcontrols.play();
    284             //    } 
    285 
    286 
    287             //  }
    288             #endregion
    289             //如果歌曲当前的播放时间等于歌曲的总时间 则下一曲
    290             //if (musicPlayer.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
    291             //{
    292             //    //获得当前选中项的索引
    293             //    int index = listBox1.SelectedIndex;
    294 
    295             //    //清空所有选中项的索引
    296             //    listBox1.SelectedIndices.Clear();
    297             //    index++;
    298             //    if (index == listBox1.Items.Count)
    299             //    {
    300             //        index = 0;
    301             //    }
    302             //    //将改变后的索引重新的赋值给当前选中项的索引
    303             //    listBox1.SelectedIndex = index;
    304             //    musicPlayer.URL = listPath[index];
    305 
    306             //}
    307             //if (musicPlayer.playState == WMPLib.WMPPlayState.wmppsReady)
    308             //{
    309             //    musicPlayer.Ctlcontrols.play();
    310             //}
    311 
    312 
    313 
    314 
    315         }
    316 
    317 
    318         /// <summary>
    319         /// 当播放器状态发生改变的时候 我输出当前播放器的播放状态
    320         /// </summary>
    321         /// <param name="sender"></param>
    322         /// <param name="e"></param>
    323         private void musicPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    324         {
    325             //  MessageBox.Show(musicPlayer.playState.ToString());
    326             if (musicPlayer.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
    327             {
    328                 //获得当前选中项的索引
    329                 int index = listBox1.SelectedIndex;
    330 
    331                 //清空所有选中项的索引
    332                 listBox1.SelectedIndices.Clear();
    333                 index++;
    334                 if (index == listBox1.Items.Count)
    335                 {
    336                     index = 0;
    337                 }
    338                 //将改变后的索引重新的赋值给当前选中项的索引
    339                 listBox1.SelectedIndex = index;
    340                 musicPlayer.URL = listPath[index];
    341 
    342             }
    343             if (musicPlayer.playState == WMPLib.WMPPlayState.wmppsReady)
    344             {
    345                 try
    346                 {
    347                     musicPlayer.Ctlcontrols.play();
    348                 }
    349                 catch { }
    350             }
    351 
    352 
    353         }
    354 
    355 
    356 
    357         //开始做歌词
    358         void IsExistLrc(string songPath)
    359         {
    360             //清空两个集合的内容
    361 
    362             songPath += ".lrc";
    363             if (File.Exists(songPath))
    364             {
    365                 //读取歌词文件
    366                 string[] lrcText = File.ReadAllLines(songPath,Encoding.Default);
    367                 //格式化歌词
    368                 FormatLrc(lrcText);
    369             }
    370             else//不存在歌词
    371             {
    372                 label2.Text = "---------歌词未找到---------";
    373             }
    374 
    375         }
    376         //存储时间
    377         List<double> listTime = new List<double>();
    378         //存储歌词
    379         List<string> listLrcText = new List<string>();
    380 
    381 
    382         /// <summary>
    383         /// 格式化歌词
    384         /// </summary>
    385         /// <param name="lrcText"></param>
    386         void FormatLrc(string[] lrcText)
    387         {
    388             for (int i = 0; i < lrcText.Length; i++)
    389             {
    390                 //[00:15.57]当我和世界不一样
    391                 string[] lrcTemp = lrcText[i].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
    392                 //00:15.57   lrcTemp[0]
    393                 //当我和世界不一样 lrcTemp[1]
    394                 string[] lrcNewTemp = lrcTemp[0].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
    395                 //00 lrcNewTemp[0]
    396                 //15.57 lrcNewTemp[1]
    397                 double time = double.Parse(lrcNewTemp[0]) * 60 + double.Parse(lrcNewTemp[1]);
    398                 //把截取出来的时间加到泛型集合中
    399                 listTime.Add(time);
    400                 //把这个时间所对应的歌词存储到泛型集合中
    401                 listLrcText.Add(lrcTemp[1]);
    402             }
    403         }
    404 
    405 
    406         /// <summary>
    407         /// 播放歌词
    408         /// </summary>
    409         /// <param name="sender"></param>
    410         /// <param name="e"></param>
    411         private void timer2_Tick(object sender, EventArgs e)
    412         {
    413             for (int i = 0; i < listTime.Count; i++)
    414             {
    415                 if (musicPlayer.Ctlcontrols.currentPosition >= listTime[i] && musicPlayer.Ctlcontrols.currentPosition < listTime[i + 1])
    416                 {
    417                     label2.Text = listLrcText[i];
    418                 }
    419             }
    420 
    421         }
    422 
    423 
    424     }
    425 }
    View Code
      1 namespace 播放器项目
      2 {
      3     partial class Form1
      4     {
      5         /// <summary>
      6         /// 必需的设计器变量。
      7         /// </summary>
      8         private System.ComponentModel.IContainer components = null;
      9 
     10         /// <summary>
     11         /// 清理所有正在使用的资源。
     12         /// </summary>
     13         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
     14         protected override void Dispose(bool disposing)
     15         {
     16             if (disposing && (components != null))
     17             {
     18                 components.Dispose();
     19             }
     20             base.Dispose(disposing);
     21         }
     22 
     23         #region Windows 窗体设计器生成的代码
     24 
     25         /// <summary>
     26         /// 设计器支持所需的方法 - 不要
     27         /// 使用代码编辑器修改此方法的内容。
     28         /// </summary>
     29         private void InitializeComponent()
     30         {
     31             this.components = new System.ComponentModel.Container();
     32             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
     33             this.musicPlayer = new AxWMPLib.AxWindowsMediaPlayer();
     34             this.button1 = new System.Windows.Forms.Button();
     35             this.button2 = new System.Windows.Forms.Button();
     36             this.groupBox1 = new System.Windows.Forms.GroupBox();
     37             this.btnPlayorPause = new System.Windows.Forms.Button();
     38             this.button3 = new System.Windows.Forms.Button();
     39             this.button4 = new System.Windows.Forms.Button();
     40             this.listBox1 = new System.Windows.Forms.ListBox();
     41             this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
     42             this.删除ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     43             this.button5 = new System.Windows.Forms.Button();
     44             this.button6 = new System.Windows.Forms.Button();
     45             this.label1 = new System.Windows.Forms.Label();
     46             this.button7 = new System.Windows.Forms.Button();
     47             this.button8 = new System.Windows.Forms.Button();
     48             this.lblInformation = new System.Windows.Forms.Label();
     49             this.timer1 = new System.Windows.Forms.Timer(this.components);
     50             this.label2 = new System.Windows.Forms.Label();
     51             this.timer2 = new System.Windows.Forms.Timer(this.components);
     52             this.pictureBox1 = new System.Windows.Forms.PictureBox();
     53             ((System.ComponentModel.ISupportInitialize)(this.musicPlayer)).BeginInit();
     54             this.groupBox1.SuspendLayout();
     55             this.contextMenuStrip1.SuspendLayout();
     56             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
     57             this.SuspendLayout();
     58             // 
     59             // musicPlayer
     60             // 
     61             this.musicPlayer.Enabled = true;
     62             this.musicPlayer.Location = new System.Drawing.Point(32, 12);
     63             this.musicPlayer.Name = "musicPlayer";
     64             this.musicPlayer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("musicPlayer.OcxState")));
     65             this.musicPlayer.Size = new System.Drawing.Size(503, 131);
     66             this.musicPlayer.TabIndex = 0;
     67             this.musicPlayer.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(this.musicPlayer_PlayStateChange);
     68             // 
     69             // button1
     70             // 
     71             this.button1.Location = new System.Drawing.Point(20, 14);
     72             this.button1.Name = "button1";
     73             this.button1.Size = new System.Drawing.Size(75, 23);
     74             this.button1.TabIndex = 1;
     75             this.button1.Text = "播放";
     76             this.button1.UseVisualStyleBackColor = true;
     77             this.button1.Click += new System.EventHandler(this.button1_Click);
     78             // 
     79             // button2
     80             // 
     81             this.button2.Location = new System.Drawing.Point(20, 43);
     82             this.button2.Name = "button2";
     83             this.button2.Size = new System.Drawing.Size(75, 23);
     84             this.button2.TabIndex = 2;
     85             this.button2.Text = "暂停";
     86             this.button2.UseVisualStyleBackColor = true;
     87             this.button2.Click += new System.EventHandler(this.button2_Click);
     88             // 
     89             // groupBox1
     90             // 
     91             this.groupBox1.Controls.Add(this.button2);
     92             this.groupBox1.Controls.Add(this.button1);
     93             this.groupBox1.Location = new System.Drawing.Point(530, 12);
     94             this.groupBox1.Name = "groupBox1";
     95             this.groupBox1.Size = new System.Drawing.Size(100, 81);
     96             this.groupBox1.TabIndex = 4;
     97             this.groupBox1.TabStop = false;
     98             this.groupBox1.Text = "老版播放器";
     99             // 
    100             // btnPlayorPause
    101             // 
    102             this.btnPlayorPause.Location = new System.Drawing.Point(21, 211);
    103             this.btnPlayorPause.Name = "btnPlayorPause";
    104             this.btnPlayorPause.Size = new System.Drawing.Size(88, 23);
    105             this.btnPlayorPause.TabIndex = 5;
    106             this.btnPlayorPause.Text = "播放";
    107             this.btnPlayorPause.UseVisualStyleBackColor = true;
    108             this.btnPlayorPause.Click += new System.EventHandler(this.btnPlayorPause_Click);
    109             // 
    110             // button3
    111             // 
    112             this.button3.Location = new System.Drawing.Point(132, 210);
    113             this.button3.Name = "button3";
    114             this.button3.Size = new System.Drawing.Size(75, 23);
    115             this.button3.TabIndex = 6;
    116             this.button3.Text = "停止";
    117             this.button3.UseVisualStyleBackColor = true;
    118             this.button3.Click += new System.EventHandler(this.button3_Click_1);
    119             // 
    120             // button4
    121             // 
    122             this.button4.Location = new System.Drawing.Point(530, 109);
    123             this.button4.Name = "button4";
    124             this.button4.Size = new System.Drawing.Size(75, 23);
    125             this.button4.TabIndex = 7;
    126             this.button4.Text = "打开";
    127             this.button4.UseVisualStyleBackColor = true;
    128             this.button4.Click += new System.EventHandler(this.button4_Click);
    129             // 
    130             // listBox1
    131             // 
    132             this.listBox1.ContextMenuStrip = this.contextMenuStrip1;
    133             this.listBox1.FormattingEnabled = true;
    134             this.listBox1.ItemHeight = 12;
    135             this.listBox1.Location = new System.Drawing.Point(530, 139);
    136             this.listBox1.Name = "listBox1";
    137             this.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
    138             this.listBox1.Size = new System.Drawing.Size(120, 232);
    139             this.listBox1.TabIndex = 8;
    140             this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
    141             // 
    142             // contextMenuStrip1
    143             // 
    144             this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    145             this.删除ToolStripMenuItem});
    146             this.contextMenuStrip1.Name = "contextMenuStrip1";
    147             this.contextMenuStrip1.Size = new System.Drawing.Size(101, 26);
    148             // 
    149             // 删除ToolStripMenuItem
    150             // 
    151             this.删除ToolStripMenuItem.Name = "删除ToolStripMenuItem";
    152             this.删除ToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
    153             this.删除ToolStripMenuItem.Text = "删除";
    154             this.删除ToolStripMenuItem.Click += new System.EventHandler(this.删除ToolStripMenuItem_Click);
    155             // 
    156             // button5
    157             // 
    158             this.button5.Location = new System.Drawing.Point(294, 210);
    159             this.button5.Name = "button5";
    160             this.button5.Size = new System.Drawing.Size(75, 23);
    161             this.button5.TabIndex = 9;
    162             this.button5.Text = "上一曲";
    163             this.button5.UseVisualStyleBackColor = true;
    164             this.button5.Click += new System.EventHandler(this.button5_Click);
    165             // 
    166             // button6
    167             // 
    168             this.button6.Location = new System.Drawing.Point(294, 240);
    169             this.button6.Name = "button6";
    170             this.button6.Size = new System.Drawing.Size(75, 23);
    171             this.button6.TabIndex = 10;
    172             this.button6.Text = "下一曲";
    173             this.button6.UseVisualStyleBackColor = true;
    174             this.button6.Click += new System.EventHandler(this.button6_Click);
    175             // 
    176             // label1
    177             // 
    178             this.label1.Location = new System.Drawing.Point(294, 270);
    179             this.label1.Name = "label1";
    180             this.label1.Size = new System.Drawing.Size(114, 113);
    181             this.label1.TabIndex = 12;
    182             this.label1.Tag = "1";
    183             this.label1.Click += new System.EventHandler(this.label1_Click);
    184             // 
    185             // button7
    186             // 
    187             this.button7.Location = new System.Drawing.Point(390, 211);
    188             this.button7.Name = "button7";
    189             this.button7.Size = new System.Drawing.Size(75, 23);
    190             this.button7.TabIndex = 13;
    191             this.button7.Text = "+";
    192             this.button7.UseVisualStyleBackColor = true;
    193             this.button7.Click += new System.EventHandler(this.button7_Click);
    194             // 
    195             // button8
    196             // 
    197             this.button8.Location = new System.Drawing.Point(390, 241);
    198             this.button8.Name = "button8";
    199             this.button8.Size = new System.Drawing.Size(75, 23);
    200             this.button8.TabIndex = 14;
    201             this.button8.Text = "-";
    202             this.button8.UseVisualStyleBackColor = true;
    203             this.button8.Click += new System.EventHandler(this.button8_Click);
    204             // 
    205             // lblInformation
    206             // 
    207             this.lblInformation.AutoSize = true;
    208             this.lblInformation.Location = new System.Drawing.Point(200, 270);
    209             this.lblInformation.Name = "lblInformation";
    210             this.lblInformation.Size = new System.Drawing.Size(41, 12);
    211             this.lblInformation.TabIndex = 15;
    212             this.lblInformation.Text = "label2";
    213             // 
    214             // timer1
    215             // 
    216             this.timer1.Enabled = true;
    217             this.timer1.Interval = 1;
    218             this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
    219             // 
    220             // label2
    221             // 
    222             this.label2.AutoSize = true;
    223             this.label2.Location = new System.Drawing.Point(19, 324);
    224             this.label2.Name = "label2";
    225             this.label2.Size = new System.Drawing.Size(41, 12);
    226             this.label2.TabIndex = 16;
    227             this.label2.Text = "label2";
    228             // 
    229             // timer2
    230             // 
    231             this.timer2.Enabled = true;
    232             this.timer2.Interval = 1000;
    233             this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
    234             // 
    235             // pictureBox1
    236             // 
    237             this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
    238             this.pictureBox1.Location = new System.Drawing.Point(32, 12);
    239             this.pictureBox1.Name = "pictureBox1";
    240             this.pictureBox1.Size = new System.Drawing.Size(503, 131);
    241             this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
    242             this.pictureBox1.TabIndex = 17;
    243             this.pictureBox1.TabStop = false;
    244             // 
    245             // Form1
    246             // 
    247             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
    248             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    249             this.ClientSize = new System.Drawing.Size(710, 392);
    250             this.Controls.Add(this.pictureBox1);
    251             this.Controls.Add(this.label2);
    252             this.Controls.Add(this.lblInformation);
    253             this.Controls.Add(this.button8);
    254             this.Controls.Add(this.button7);
    255             this.Controls.Add(this.label1);
    256             this.Controls.Add(this.button6);
    257             this.Controls.Add(this.button5);
    258             this.Controls.Add(this.listBox1);
    259             this.Controls.Add(this.button4);
    260             this.Controls.Add(this.button3);
    261             this.Controls.Add(this.btnPlayorPause);
    262             this.Controls.Add(this.groupBox1);
    263             this.Controls.Add(this.musicPlayer);
    264             this.Name = "Form1";
    265             this.Text = "Form1";
    266             this.Load += new System.EventHandler(this.Form1_Load);
    267             ((System.ComponentModel.ISupportInitialize)(this.musicPlayer)).EndInit();
    268             this.groupBox1.ResumeLayout(false);
    269             this.contextMenuStrip1.ResumeLayout(false);
    270             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
    271             this.ResumeLayout(false);
    272             this.PerformLayout();
    273 
    274         }
    275 
    276         #endregion
    277 
    278         private AxWMPLib.AxWindowsMediaPlayer musicPlayer;
    279         private System.Windows.Forms.Button button1;
    280         private System.Windows.Forms.Button button2;
    281         private System.Windows.Forms.GroupBox groupBox1;
    282         private System.Windows.Forms.Button btnPlayorPause;
    283         private System.Windows.Forms.Button button3;
    284         private System.Windows.Forms.Button button4;
    285         private System.Windows.Forms.ListBox listBox1;
    286         private System.Windows.Forms.Button button5;
    287         private System.Windows.Forms.Button button6;
    288         private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
    289         private System.Windows.Forms.ToolStripMenuItem 删除ToolStripMenuItem;
    290         private System.Windows.Forms.Label label1;
    291         private System.Windows.Forms.Button button7;
    292         private System.Windows.Forms.Button button8;
    293         private System.Windows.Forms.Label lblInformation;
    294         private System.Windows.Forms.Timer timer1;
    295         private System.Windows.Forms.Label label2;
    296         private System.Windows.Forms.Timer timer2;
    297         private System.Windows.Forms.PictureBox pictureBox1;
    298     }
    299 }
    View Code
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Threading.Tasks;
     5 using System.Windows.Forms;
     6 
     7 namespace 播放器项目
     8 {
     9     static class Program
    10     {
    11         /// <summary>
    12         /// 应用程序的主入口点。
    13         /// </summary>
    14         [STAThread]
    15         static void Main()
    16         {
    17             Application.EnableVisualStyles();
    18             Application.SetCompatibleTextRenderingDefault(false);
    19             Application.Run(new Form1());
    20         }
    21     }
    22 }
    View Code
  • 相关阅读:
    yum 在线安装LAMP
    python-scrapy-增量式
    python-scrapy-分布式爬取
    python-scrapy-全站数据爬取-CrawlSpider
    python-scrapy-中间件的学习
    python-scrapy深度爬取
    python-scrapy环境配置
    django DOM
    window10设置环境变量(以设置虚拟环境和SQL为例)
    加入园子啦
  • 原文地址:https://www.cnblogs.com/liuslayer/p/4713736.html
Copyright © 2011-2022 走看看