码迷,mamicode.com
首页 > Windows程序 > 详细

C# 多媒体播放器

时间:2014-12-09 23:03:35      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:blog   ar   os   sp   for   on   文件   div   log   

   //停止播放
        public void stopFile()
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }

        //暂停文件
        public void pauseFile()
        {
              axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

        //播放文件
        public void starFile()
        {
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

        //列表清空
        public void clearFile()
        {
            listBox1.Items.Clear();
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }
        private void 全屏ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                axWindowsMediaPlayer1.fullScreen = !axWindowsMediaPlayer1.fullScreen;
            }
        }
   private String file = "";
        List<string> list = new List<string>();
        //删除单个文件
        public void delFile()
        {
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                if (listBox1.SelectedItems.Contains(listBox1.Items[i]))
                {
                    listBox1.Items.Remove(listBox1.Items[i]);
                    axWindowsMediaPlayer1.Ctlcontrols.stop();

                }
            }
        }

   private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
          
            DialogResult dr = openFileDialog1.ShowDialog();
            openFileDialog1.Multiselect = true;
            switch (dr)
            { 
                case DialogResult.OK:
                    file = openFileDialog1.FileName;
                    list.Add(file);
                    axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
                    listBox1.Items.Add( openFileDialog1.FileName.Substring(file.LastIndexOf("\\")+1));
                    break;
                case DialogResult.No:
                    break;
            }
        }

  private void button5_Click(object sender, EventArgs e)
        {
            starFile();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            pauseFile();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            stopFile();
        }

        //上一曲
        private void button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                if (listBox1.SelectedItems.Contains(listBox1.Items[i]))
                {
                    //如果是顶部
                    if (listBox1.SelectedIndex == 0)
                    {
                        MessageBox.Show("已经达到顶部");
  
                    }
                    //否则就上一曲
                    else
                    {

                        listBox1.SetSelected(listBox1.SelectedIndex - 1, true);
                        axWindowsMediaPlayer1.URL = list[listBox1.SelectedIndex];

                        return;
                    }
                    
                }
            }
        }
        //下一曲
        private void button4_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                if (listBox1.SelectedItems.Contains(listBox1.Items[i]))
                {
                    //如果是顶部
                    if (listBox1.SelectedIndex == listBox1.Items.Count - 1)
                    {
                        MessageBox.Show("已经达到尾部部");
                        //MessageBox.Show(listBox1.Items.Count.ToString());
                    }
                    //否则就下一曲
                    else
                    {

                        listBox1.SetSelected(listBox1.SelectedIndex+1, true);
                        //让歌曲切换到下一曲
                        axWindowsMediaPlayer1.URL = list[listBox1.SelectedIndex];
                        return;
                    }

                }
            }
        }

        private void 全选列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
                listBox1.MultiColumn = true;   
                //listBox1.SetSelected(0, true);
                //listBox1.SetSelected(1, true);
                //listBox1.SetSelected(2, true);
            
            listBox1.Select();
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            delFile();
        }

        private void 播放ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            starFile();
        }

        private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            stopFile();
        }

        private void 暂停ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pauseFile();
        }

        private void 快退ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.fastReverse();
        }

        private void 快进ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.fastForward();
        }

        private void 清空ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            delFile();
        }

 

C# 多媒体播放器

标签:blog   ar   os   sp   for   on   文件   div   log   

原文地址:http://www.cnblogs.com/codemouserman/p/4154364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!