• WinForm中实现播放mp3 、mp4文件


    来自:http://www.cnblogs.com/duanchen/p/4445478.html

    1、在Vs2012 工具箱右键-->"选择项"-->"Com组件"-->"Windows Media Player" 勾上,然后点击确定。

    2、在WinForm 窗体中添加两个 button按钮,一个Windows Media Player,相应

    按钮代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    //播放音乐
    private void button1_Click(object sender, EventArgs e)
            {
                FileDialog open = new OpenFileDialog();
                //wxWindowsMediaplayer1是控件名
                this.axWindowsMediaPlayer1.settings.playCount = 2;//播放次数;
                open.Filter = "*.mp3|*.mp3";
                open.Title = "打开文件";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    axWindowsMediaPlayer1.URL = open.FileName;
                    axWindowsMediaPlayer1.Ctlcontrols.play();//播放文件
                }
            }
     
     
     //播放视频
     private void button2_Click(object sender, EventArgs e)
            {
                FileDialog open = new OpenFileDialog();
                //wxWindowsMediaplayer1是控件名
                this.axWindowsMediaPlayer1.settings.playCount = 2;//播放次数;
                open.Filter = "*.mp4|*.mp4"; //文件格式
                open.Title = "打开文件";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    axWindowsMediaPlayer1.URL = open.FileName;
                    axWindowsMediaPlayer1.Ctlcontrols.play();//播放文件
                }
            }

    效果图:

    如果有不对的地方,望园子中的朋友加以指出!

  • 相关阅读:
    laravel 汇总数据
    Sway
    利用 Windows API Code Pack 修改音乐的 ID3 信息
    Windows Server 2012 R2 设置 NTP 服务
    Visual Studio "14" CTPs
    Win8.1 查看 “Windows 体验指数“
    json2csharp & json 格式化
    山寨版 WP8.1 Cortana 启动 PC
    Newtonsoft.Json WindowPhone7.1
    Cisco交换机基础命令 + Win Server08 R2 多网卡配置链路聚合
  • 原文地址:https://www.cnblogs.com/gisoracle/p/6026580.html
Copyright © 2020-2023  润新知