自学的简易播放器(C#)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;

namespace myplayer
{
    public partial class Form1 : Form
    {
        public Form1()
        {     
            InitializeComponent();
        }
        OpenFileDialog ofd = new OpenFileDialog();
       //打开歌曲,加入列表
        private void button1_Click(object sender, EventArgs e)
        {
            ofd.Filter = "MP3格式(*.mp3)|*.mp3|音频格式(*.wav)|*.wav|所有文件(*.*)|*.*";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                listBox1.Items.Add(ofd.FileName);
            }
        }
        //播放当前选择的歌曲
        private void button6_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
         
        }
        //删除当前选择歌曲
        private void button3_Click(object sender, EventArgs e)
        {
            if (ofd.FileName ==listBox1.SelectedItem.ToString())
            {
                listBox1.Items.Remove(listBox1.SelectedItem);
            }

        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox1.Select();
           
        }
        //双击歌曲播放
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.URL=  listBox1.SelectedItem.ToString();

        }
        //当前曲目的上一首
        private void before_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex > 0)
            {
                listBox1.SelectedIndex -= 1;
                axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();

            }
            else
            {
                listBox1.SelectedIndex = listBox1.Items.Count - 1;
                axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
            }
        }
        //循环播放
        private void circle_Click(object sender, EventArgs e)
        {

        }
        //播放当前曲目的下一首
        private void next_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < listBox1.Items.Count - 1)
            {
                listBox1.SelectedIndex += 1;
                axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
            }
            else
            {
                listBox1.SelectedIndex = 0;
                axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
            }
        }
    }
}
 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值