注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

蓝星天宇

爱生活,爱分享!

 
 
 

日志

 
 

天宇媒体播放器  

2010-05-22 10:23:50|  分类: 计算机编程类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
天宇媒体播放器 - 蓝星天宇 - 中国·天宇网易博客
 
天宇媒体播放器 - 蓝星天宇 - 中国·天宇网易博客
 
天宇媒体播放器 - 蓝星天宇 - 中国·天宇网易博客
 
天宇媒体播放器 - 蓝星天宇 - 中国·天宇网易博客
 
天宇媒体播放器 - 蓝星天宇 - 中国·天宇网易博客
 
本程序由天宇设计,版权所有,违者必究!
源码如下,仅供学习参考使用
-------------------------------------------------------------------------------------------------------------------------------------------------
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.Xml;//用于将歌曲列表文件保存在XML文件中……
namespace TYPlayer
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            //加载程序的时候读取XML文件 加载播放列表 它就相当于一个移动的数据库 良好的跨平台性
            try
            {
                //XmlDocument xmlDoc =new XmlDocument();
                //xmlDoc.Load("D:\\TY.xml");
                //AddWithChildren(xnod,0);
                XmlTextReader reader = new XmlTextReader(Application.StartupPath + "
");
                while (reader.Read())
                {
                    if (reader.Name == "文件名")
                    {
                        menuList.Items.Add(reader.ReadString());
                    }
                }
            }
            catch (Exception ex)
            { }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            pnlList.Visible = !pnlList.Visible;
            //-------------------------------------------
            Player.Focus();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            Random rdom = new Random();
            Color color = Color.FromArgb(rdom.Next(0, 255), rdom.Next(0, 255), rdom.Next(0, 255));
            btnAddFile.ForeColor = color;
            btnAddPackage.ForeColor = color;
            btnRemoveAll.ForeColor = color;
            btnRemoveFile.ForeColor = color;
        }
        private void btnAddFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFile = new OpenFileDialog();
                openFile.InitialDirectory = @"C:\";
                openFile.Filter = "媒体文件(*.mp3;*.wma;*.wmv;*.rmvb;*.rm;*.3gp;*.mp4)|*.mp3;*.wma;*.wmv;*.rmvb;*.rm;*.3gp;*.mp4";
                DialogResult dr = openFile.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    string singlefile = openFile.FileName;
                    menuList.Items.Add(singlefile);
                }
            }
            catch
            {
                MessageBox.Show("添加文件出错!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //-------------------------------------------
            menuList.Focus();
        }
        private void btnAddPackage_Click(object sender, EventArgs e)
        {
            try
            {
                    FolderBrowserDialog folderDr = new FolderBrowserDialog();
                    DialogResult dr=folderDr.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        string packagepath = folderDr.SelectedPath;
                        DirectoryInfo TheFolder = new DirectoryInfo(packagepath);
                        foreach (FileInfo NextFile in TheFolder.GetFiles())
                        {
                            if (NextFile.Extension == ".mp3" || NextFile.Extension == ".wma" || NextFile.Extension == ".wmv" || NextFile.Extension == ".rmvb" || NextFile.Extension == ".rm" || NextFile.Extension == ".3gp" || NextFile.Extension == ".mp4")
                            {
                                menuList.Items.Add(NextFile.FullName);
                            }
                        }
                    }
            }
            catch
            {
                MessageBox.Show("添加文件夹文件出错!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //-------------------------------------------
            menuList.Focus();
        }
        bool blRemoveAt = true;
        private void btnRemoveFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (blRemoveAt)
                {
                    DialogResult dr = MessageBox.Show("您确定要移除此文件吗?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        Player.Ctlcontrols.stop();
                        menuList.Items.RemoveAt(menuList.SelectedIndex);
                        blRemoveAt = false;
                    }
                    blRemoveAt = true;
                }
                //-------------------------------------------
                menuList.Focus();
            }
            catch (Exception ex)
            {
              
            }
        }
        bool blRemoveAll = true;
        private void btnRemoveAll_Click(object sender, EventArgs e)
        {
            try
            {
                if (blRemoveAll)
                {
                    DialogResult dr = MessageBox.Show("您确定要清空播放列表吗?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        menuList.Items.Clear();
                        blRemoveAll = false;
                    }
                    blRemoveAll = true;
                }
                //-------------------------------------------
                menuList.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show("移除所有文件时出错!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Player.fullScreen = !Player.fullScreen;
            }
            catch(Exception ex)
            {
                MessageBox.Show("请在节目开始后使用此功能!","温馨提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                //-------------------------------------------
                Player.Focus();
            }
        }
        //点击列表项 播放文件
        private void menuList_SelectedIndexChanged(object sender,EventArgs e)
        {
            try
            {
                Player.URL = menuList.SelectedItem.ToString();
                Player.Ctlcontrols.play();
            }
            catch (Exception ex)
            {
              
            }
        }
        //单击图片 跳转……
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("explorer.exe", "
http://besttianqi.blog.163.com/");
        }
        bool flag = true;
        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag)
            {
                DialogResult dr = MessageBox.Show("确定要退出吗?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    //删除原来文件
                    //关闭程序之前 将数据重新写入XML文件
                    //创建一个XML文件对象
                    XmlDataDocument xmlDoc = new XmlDataDocument();
                    //创建一个XML节点
                    XmlNode xmlNode = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration,"","");
                    XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
                    xmlDoc.AppendChild(xmlDeclaration);
                    //创建根元素
                    XmlElement xmlElement = xmlDoc.CreateElement("媒体文件");
                    xmlDoc.AppendChild(xmlElement);
                    //添加子元素和元素属性
                    int menuListCount = menuList.Items.Count;
                    for (int i = 0; i < menuListCount; i++)
                    {
                        XmlElement xmlChildElement= xmlDoc.CreateElement("文件名");
                        XmlText xmlText = xmlDoc.CreateTextNode(Convert.ToString(menuList.Items[i]));
                        xmlChildElement.AppendChild(xmlText);
                        xmlElement.AppendChild(xmlChildElement);
                    }
                    //保存XML文件
                    //保存xml文件对象  
                    try
                    {
                        xmlDoc.Save(Application.StartupPath + "
"); //XML文件保存在当前应用程序工作目录
                    }
                    catch (Exception ex)
                    {}
                    //……
                    flag = false;
                    Application.Exit();
                }
                else
                {
                    e.Cancel = true;
                }
            }
        }
        /// <summary>
        /// 以下是设置自动播放……
        /// </summary>
        double timemedia = 0;
        private void timerNext_Tick(object sender, EventArgs e)
        {
            try
            {
                if (Player.currentMedia != null)
                {
                    double songtime = Player.currentMedia.duration;
                    timemedia = Player.Ctlcontrols.currentPosition;
                    if (timemedia < songtime)
                    {
                        timemedia++;
                    }
                    if (timemedia == songtime || timemedia > songtime)
                    {
                        menuList.SelectedIndex = menuList.SelectedIndex + 1;
                        Player.URL = menuList.SelectedItem.ToString();
                        Player.Ctlcontrols.play();
                        timemedia = 0;
                    }
                }
            }
            catch (Exception ex) { }
        }
    }
}
 此程序开发使用C# 语言,.NET Framework 2.0运行时库进行设计!需添加微软Windows media player控件,具体教程在前面有介绍过!
  评论这张
 
阅读(694)| 评论(2)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016