| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7155 人关注过本帖
标题:自编mp3音乐播放器
只看楼主 加入收藏
zkmhywgsym
Rank: 2
等 级:论坛游民
帖 子:38
专家分:98
注 册:2011-3-5
收藏
得分:0 
2011-04-12 18:40
angelline
Rank: 1
等 级:新手上路
帖 子:18
专家分:3
注 册:2011-4-11
收藏
得分:0 
这个怎么弄出来的 源码分享一下
2011-04-13 12:09
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
回复 12楼 angelline
我上传的就是整个工程,你下下来就有了!

   唯实惟新 至诚致志
2011-04-13 18:03
zhangyf0303
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-3-26
收藏
得分:0 
打不开啊~~~没看到代码....求指教
2011-04-13 21:44
zhangyf0303
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-3-26
收藏
得分:0 
OK了。。。打开了,一开始没找到
2011-04-13 21:46
a101069
Rank: 2
等 级:论坛游民
帖 子:18
专家分:64
注 册:2011-4-10
收藏
得分:0 
请教lz,随机播放怎么写啊/?请教lz,随机播放怎么写啊/?
2011-04-13 21:51
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
回复 16楼 a101069
这个还要考虑一下。应该是另外建立一个播放列表,由已存在的列表中随机生成,然后用这个列表来播放!还不知道怎么样新建列表!

   唯实惟新 至诚致志
2011-04-13 22:05
ak110240
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2010-9-19
收藏
得分:0 
求源代码 !可否给我看看!
2011-04-13 22:36
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using namespace MusicPlayer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.BeginInit();  //初始化
            axWindowsMediaPlayer1.settings.autoStart = true;  //自动播放
            axWindowsMediaPlayer1.settings.setMode("shuffle", false);  //顺序播放
            axWindowsMediaPlayer1.settings.enableErrorDialogs = true;
            axWindowsMediaPlayer1.settings.balance = 0;
            axWindowsMediaPlayer1.settings.mute = false;
            axWindowsMediaPlayer1.settings.volume = 100;  //声音设为最大
            //btnBack.Enabled = false;  //声音不对
            //btnForward.Enabled = false;  //声音不对
            //btnBE.Enabled = false;  //无法暂停和开始
        

            if (File.Exists("listbox.txt"))  //如果存在播放列表,那么加载播放列表
            {
                StreamReader reader = new StreamReader("listbox.txt");
                try
                {
                    while (reader.Peek() != -1)
                    {
                        string filepath = reader.ReadLine();
                        string filename = Path.GetFileName(filepath);
                        listBox1.Items.Add(filename);  //listbox用来显示歌曲名
                        axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(filepath));
                    }
                    listBox1.SelectedIndex = 0;
                }
                catch (Exception)
                {
                    listBox1.SelectedIndex = -1;
                    MessageBox.Show("加载播放列表失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    reader.Close();
                }
            }

        }

        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)  //打开音乐文件,但不加入到播放列表中
        {
            DialogResult dr = openFileDialog1.ShowDialog();

            if (dr == DialogResult.OK)
            {
                axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
            }
        }

        private void ExitToolStripMenuItem_Click(object sender, EventArgs e)  //结束程序,但为什么不起作用?而共享此动作的btnExit却有作用?
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
            axWindowsMediaPlayer1.close();
            Application.Exit();
        }

        private void AddSingleToolStripMenuItem_Click(object sender, EventArgs e)  //添加单首歌曲到播放列表中,"添加"按钮共享此事件
        {
            DialogResult dr = openFileDialog1.ShowDialog();

            if (dr == DialogResult.OK)
            {
                string filepath = openFileDialog1.FileName;
                string filename = Path.GetFileName(filepath);
                listBox1.Items.Add(filename);

                axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count,axWindowsMediaPlayer1.newMedia(filepath));
            }
        }

        private void AddMoreToolStripMenuItem_Click(object sender, EventArgs e)  //添加选中的文件夹中的mp3文件到播放列表中
        {
            DialogResult dr = folderBrowserDialog1.ShowDialog();

            if (dr == DialogResult.OK)
            {
                string[] filepath = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
                foreach (string s in filepath)
                {
                    if (Path.GetExtension(s) == ".mp3")
                    {
                        string filename = Path.GetFileName(s);
                        listBox1.Items.Add(filename);

                        axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(s));
                    }
                }
            }
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)  //播放列表中选中的歌曲
        {
            int j = listBox1.SelectedIndex;
            if(listBox1.Items.Count>0)
            {
                axWindowsMediaPlayer1.Ctlcontrols.playItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(j));
            }
        }

      
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)  //退出程序的动作
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
            axWindowsMediaPlayer1.close();  //关闭播放器
           
            StreamWriter writer = new StreamWriter("listbox.txt",false,Encoding.Unicode);  //保存播放列表
            for (int i = 0; i < axWindowsMediaPlayer1.currentPlaylist.count; i++)
            {
                writer.WriteLine(axWindowsMediaPlayer1.currentPlaylist.get_Item(i).sourceURL);
            }
            writer.Close();

        }

        private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)  //显示播放状态
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                label1.Text = "正在播放 " + axWindowsMediaPlayer1.currentMedia.sourceURL+"   "+axWindowsMediaPlayer1.currentMedia.durationString;
                string s = axWindowsMediaPlayer1.currentMedia.sourceURL;
                for (int i = 0; i < axWindowsMediaPlayer1.currentPlaylist.count; i++)
                {
                    if (listBox1.Items[i].ToString() == Path.GetFileName(s))
                    {
                        listBox1.SelectedIndex = i;
                        break;
                    }
                }
            }
         
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsBuffering)
            {
                label1.Text = "正在缓冲 " + axWindowsMediaPlayer1.currentMedia.sourceURL;
            }
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused)
            {
                label1.Text = "暂停播放 " + axWindowsMediaPlayer1.currentMedia.sourceURL;
            }
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsWaiting)
            {
                label1.Text = "正在等待";
            }
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped)
            {
                label1.Text = "播放停止";
            }
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsReady)
            {
                label1.Text = "准备就绪";
            }
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsScanForward)
            {
                label1.Text = "正在快进 " + axWindowsMediaPlayer1.currentMedia.sourceURL;
            }
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsScanReverse)
            {
                label1.Text = "正在快退 " + axWindowsMediaPlayer1.currentMedia.sourceURL;
            }
        }

        private void btnBE_Click(object sender, EventArgs e)  //暂停/开始,不起作用
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                axWindowsMediaPlayer1.Ctlcontrols.pause();
            }
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused)
            {
                axWindowsMediaPlayer1.Ctlcontrols.play();
            }
        }

        private void btnStop_Click(object sender, EventArgs e)  //停止播放
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();
        }

        private void btnSlient_Click(object sender, EventArgs e)  //静音
        {
            if (axWindowsMediaPlayer1.settings.mute == false)
            {
                axWindowsMediaPlayer1.settings.mute = true;
            }
            else
            {
                axWindowsMediaPlayer1.settings.mute = false;
            }
        }

        private void btnBack_Click(object sender, EventArgs e)  //快退,声音不对
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                axWindowsMediaPlayer1.Ctlcontrols.fastReverse();
            }
        }

        private void btnForward_Click(object sender, EventArgs e)  //快进,声音不对
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                axWindowsMediaPlayer1.Ctlcontrols.fastForward();
            }
        }

        private void btnPre_Click(object sender, EventArgs e)  //上一曲
        {
            if (listBox1.SelectedIndex != 0)
            {
                axWindowsMediaPlayer1.Ctlcontrols.previous();
            }
        }

        private void btnNext_Click(object sender, EventArgs e)  //下一曲
        {
            if (listBox1.SelectedIndex != listBox1.Items.Count - 1)
            {
                axWindowsMediaPlayer1.Ctlcontrols.next();
            }
        }

        private void btnPlay_Click(object sender, EventArgs e)  //双击播放列表中选中的歌曲
        {
            if(listBox1.Items.Count>0&&listBox1.SelectedIndex>=0)
            {
                axWindowsMediaPlayer1.Ctlcontrols.playItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(listBox1.SelectedIndex));
            }
        }

        private void btRemove_Click(object sender, EventArgs e)  //将选中的歌曲移出播放列表
        {
            int i = listBox1.SelectedIndex;
            if (listBox1.Items.Count > 0)
            {
                listBox1.Items.RemoveAt(i);
                axWindowsMediaPlayer1.currentPlaylist.removeItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(i));
            }

            if (i == listBox1.Items.Count)
            {
                listBox1.SelectedIndex = listBox1.Items.Count-1;
            }
            else
            {
                listBox1.SelectedIndex = i;
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)  //同上,并删除本地的音乐文件
        {
            if (MessageBox.Show("确定要删除文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                int i = listBox1.SelectedIndex;
                string s = axWindowsMediaPlayer1.currentPlaylist.get_Item(i).sourceURL;
                if (listBox1.Items.Count > 0)
                {
                    listBox1.Items.RemoveAt(i);
                    axWindowsMediaPlayer1.currentPlaylist.removeItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(i));
                }

                if (i == listBox1.Items.Count)
                {
                    listBox1.SelectedIndex = listBox1.Items.Count - 1;
                }
                else
                {
                    listBox1.SelectedIndex = i;
                }

                try
                {
                    File.Delete(s);
                }
                catch (Exception)
                {
                    MessageBox.Show("删除文件失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }

        }

        private void delAllToolStripMenuItem_Click(object sender, EventArgs e)  //清空播放列表
        {
            axWindowsMediaPlayer1.Ctlcontrols.stop();  //先停止播放器
            listBox1.Items.Clear();  //清空listbox
            axWindowsMediaPlayer1.currentPlaylist.clear();  //清空播放列表
        }
    }
}

   唯实惟新 至诚致志
2011-04-13 22:39
angelline
Rank: 1
等 级:新手上路
帖 子:18
专家分:3
注 册:2011-4-11
收藏
得分:0 
哇 楼主牛呢 偶要狠努力啦
2011-04-14 08:14
快速回复:自编mp3音乐播放器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030683 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved