bofangqi

来源:互联网 发布:数据库应用系统功能 编辑:程序博客网 时间:2024/06/10 17:22

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Media;

namespace player
{
    public partial class Form1 : Form
    {[DllImport("winmm.dll")]
public static extern uint mciSendString(string lpstrCommand,
            string lpstrReturnString, uint uReturnLength, uint hWndCallback);
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
          this.tbarVolume.Minimum = 0;
         this.tbarVolume.Maximum = 100;
         this.tbarVolume.Value = this.axWindowsMediaPlayer1.settings.volume; 
           // AxWMPLib.AxWindowsMediaPlayer awm = new AxWMPLib.AxWindowsMediaPlayer();
            axWindowsMediaPlayer1.settings.autoStart = true;
            axWindowsMediaPlayer1.settings.volume = 60;
        //绝对路径  
      // string path ="F:/player/player/bin/Debug/sound/一万个理由.mp3";
      //axWindowsMediaPlayer1.URL = path;
       //相对路径:
            this.axWindowsMediaPlayer1.URL = Application.StartupPath + "//sound//一万个理由.mp3";
           // this.axWindowsMediaPlayer1.uiMode = Random((this .axWindowsMediaPlayer1 .URL ).ToString ()); 
            select();
        }

        private void button4_Click(object sender, EventArgs e)
        {
                              
            if ( openFileDialog1 .ShowDialog() ==DialogResult .OK )
            {
               string s = "";
                StreamReader sr = new StreamReader(openFileDialog1 .FileName , System.Text.Encoding.Default);
                while (!sr.EndOfStream)
                {
                    s = sr.ReadToEnd() + System.Environment.NewLine;
                }
                sr.Close();
               // 方法一:
                //listView1.Items.Add(openFileDialog1.FileName);
                //this.listView1.Items[0].Selected = true; 
               //方法二:获取带绝对路径名
                listBox1.Items.AddRange(openFileDialog1.FileNames);
               //方法上:不带路径的名
                //foreach (String file in openFileDialog1.FileNames)
                //{
                //    listBox1.Items.Add(System.IO.Path.GetFileName(file));
                //} 
                    }       
   
            }
       
        public void select()
        {  if(this.listBox1 .Items .Count>0)
         {
             if (this.listBox1.SelectedItems.Count > 0)
             {
                 string[] pl = this.openFileDialog1.FileNames;
                 //int iPos = this.listBox1.SelectedItems[];
                 // string FileName=this.listBox1.Items[iPos].SubItems[3].Text;

                // int index = listBox1.SelectedIndex;//获得当前点击的索引值
                //axWindowsMediaPlayer1.URL = (string)pl.ToString ();//开始播放 
              
             }
             else { MessageBox .Show ("这是咋了的:");}
        }
              
        }

       

        private void btplay_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.play();
        }

        private void btpause_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

        private void btstop_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.stop();
        }

               private void trackBar1_Scroll(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.settings.volume = this.tbarVolume.Value;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.settings.volume += 5;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.settings.volume -= 5;
        }

        private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            string[] pl = this.openFileDialog1.FileNames;
            //this.axWindowsMediaPlayer1.URL = listBox1.SelectedValue.ToString();
            //this.axWindowsMediaPlayer1.Ctlcontrols.play();
            //this.axWindowsMediaPlayer1.currentPlaylist = this.listBox1.SelectedItems ;
            int index = listBox1.SelectedIndex;//获得当前点击的索引值
            axWindowsMediaPlayer1.URL = (string)pl[index];//开始播放
        }
    }
}

原创粉丝点击