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;

namespace VideoGoogle
{
    //选择菜单中的“工具”--“自定义工具箱”,打开“自定义工具箱”窗口,在“COM 组件”中选择“Windows Media Player”播放器和
    //“Shockwave Flash Object”flash播放器
    
    public partial class Form1 : Form
    {
        private static string PathBase = System.AppDomain.CurrentDomain.BaseDirectory;//目录

public Form1()
        {
            InitializeComponent();
        }

private void Form1_Load(object sender, EventArgs e)
        {
            //this.axWindowsMediaPlayer1.uiMode = "none";//右键axWindowsMediaPlayer1--属性--常规--控件布局--选择模式--None
            this.tbarVolume.Minimum = 0;                                               //設定音量調整Bar最小值為最小音量值(0)
            this.tbarVolume.Maximum = 100;                                             //設定音量調整Bar最大值為最大音量值(100)
            this.tbarVolume.Value = this.axWindowsMediaPlayer1.settings.volume;
        }

//打开
        private void button5_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            //设置为可以打开多个文件
            openFileDialog.Multiselect = true;
            //设置打开文件格式
            openFileDialog.Filter = "Mp3文件|*.mp3|Wav文件|*.wav|Wma文件|*.wma|Wmv文件|*.wmv|所有格式|*.*";
            //判断是否单击确定按钮
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //建立播放列表,名字为aa
                axWindowsMediaPlayer1.currentPlaylist = axWindowsMediaPlayer1.newPlaylist("aa", "");
                //遍历打开的集合
                foreach (string fn in openFileDialog.FileNames)
                {
                    //添加播放列表
                    axWindowsMediaPlayer1.currentPlaylist.appendItem(axWindowsMediaPlayer1.newMedia(fn));
                }
            }
            //播放
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

//播放视频
        private void button1_Click(object sender, EventArgs e)
        {
            string Path = PathBase + "航架2.mpg";
            this.axWindowsMediaPlayer1.URL = Path;
            this.axWindowsMediaPlayer1.Ctlcontrols.play();  
        }

//播放MP3
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();
            openFile.Filter = "mp3文件|*.mp3";
            if (DialogResult.OK == openFile.ShowDialog())
            {
                axWindowsMediaPlayer1.URL = openFile.FileName;
            }
        }

//设置
        private void button6_Click(object sender, EventArgs e)
        {
            string Duration = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("Duration");//持续时间(秒)
            string Title = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("Title");//媒体标题
            string Author = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("Author");//艺术家
            string Copyright = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("Copyright");//版权信息
            string Description = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("Description");//媒体内容描述
            string FileSize = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize");//文件大小
            string FileType = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("FileType");//文件类型
            string sourceURL = this.axWindowsMediaPlayer1.currentMedia.getItemInfo("sourceURL");//原始地址
            MessageBox.Show("持续时间:"+Duration+"||"+"媒体标题:"+Title+"||"+"艺术家:"+Author+"||"+"版权信息:"+Copyright+"||"+"媒体内容描述:"+Description+"||"+"文件大小:"+FileSize+"||"+"文件类型:"+FileType+"||"+"原始地址:"+sourceURL);

string name = this.axWindowsMediaPlayer1.currentMedia.name;
            string url = this.axWindowsMediaPlayer1.currentMedia.sourceURL;

//设置
            //this.axWindowsMediaPlayer1.currentMedia.setItemInfo("Title", "航架");

this.axWindowsMediaPlayer1.settings.balance = 0;//表示媒体播放的声道设置,0表示均衡,-1和1表示左右声道
            double rate = this.axWindowsMediaPlayer1.settings.rate;//播放速率,一般乘以16后再显示kbps单位.
            //this.axWindowsMediaPlayer1.currentMedia.setItemInfo("rate", "2");
        }

//打开Flash
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();
            ofDialog.AddExtension = true;
            ofDialog.CheckFileExists = true;
            ofDialog.CheckPathExists = true;
            ofDialog.Filter = "Flash文件(*.swf)|*.swf|所有文件(*.*)|*.*"; ;// "swf 文件 (*.swf)|*.swf|所有文件 (*.*)|*.*";
            ofDialog.DefaultExt = "mp3";
            if (ofDialog.ShowDialog() == DialogResult.OK)
            {
                this.axShockwaveFlash1.Movie = ofDialog.FileName;
            }

//==========================================
            //openFileDialog1.Filter = "Flash文件(*.swf)|*.swf|所有文件(*.*)|*.*";
            //if (openFileDialog1.ShowDialog() == DialogResult.OK)
            //{
            //    string MyFileName = openFileDialog1.FileName;
            //    this.axShockwaveFlash1.Movie = MyFileName;
            //}
        }

//Flash
        private void button3_Click(object sender, EventArgs e)
        {
            this.axShockwaveFlash1.Stop();//暂停播放
            this.axShockwaveFlash1.Rewind();//播放第一帧
            this.axShockwaveFlash1.Back();//播放上一帧
            this.axShockwaveFlash1.Forward();//开始播放
            this.axShockwaveFlash1.Rewind();//播放下一帧
            this.axShockwaveFlash1.Play();//播放下一帧
        }

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

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

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

//open
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            //设置为可以打开多个文件
            openFileDialog.Multiselect = true;
            //设置打开文件格式
            openFileDialog.Filter = "Mp3文件|*.mp3|Wav文件|*.wav|Wma文件|*.wma|Wmv文件|*.wmv|所有格式|*.*";
            //判断是否单击确定按钮
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //建立播放列表,名字为aa
                axWindowsMediaPlayer1.currentPlaylist = axWindowsMediaPlayer1.newPlaylist("aa", "");
                //遍历打开的集合
                foreach (string fn in openFileDialog.FileNames)
                {
                    //添加播放列表
                    axWindowsMediaPlayer1.currentPlaylist.appendItem(axWindowsMediaPlayer1.newMedia(fn));
                }
            }
            //播放
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

//exit
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

//上一个
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.previous();
        }

//播放
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

//下一个
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.next();
        }

//暂停
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

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

//进度
        private void timer1_Tick(object sender, EventArgs e)
        {
            double total=0.0d;
            if (this.axWindowsMediaPlayer1.currentMedia != null)
            {
                total = Math.Ceiling(this.axWindowsMediaPlayer1.currentMedia.duration);

this.tbarPlayLoaction.Maximum = (int)this.axWindowsMediaPlayer1.currentMedia.duration;//設定撥放位置調整Bar最大值                    
            }
            double cur = Math.Floor(this.axWindowsMediaPlayer1.Ctlcontrols.currentPosition);
            if (total != 0)
            {
                this.progressBar1.Value = (int)(cur / total *100);
                this.label1.Text = cur.ToString()+"s" + "/" + total.ToString()+"s";

this.tbarPlayLoaction.Value = (int)(cur / total * total);
            }

//---------------------------------
            ////循环播放
            //if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped)
            //{
            //    axWindowsMediaPlayer1.Ctlcontrols.play();
            //}
        }

//快进
        private void button7_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.fastForward();
        }

//快退
        private void button8_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.fastReverse();
        }

//自动播放
        private void autoStartToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.autoStartToolStripMenuItem.Checked)
            {
                this.axWindowsMediaPlayer1.settings.autoStart = true;
            }
        }

//播放
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.play();
        }

//暂停
        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

//显示当前音量
        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            int volume=this.axWindowsMediaPlayer1.settings.volume;
            MessageBox.Show("音量:"+volume.ToString());

//this.axWindowsMediaPlayer1.currentMedia.setItemInfo("volume", "60");     
        }

//改变音量大小
        private void tbarVolume_Scroll(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.settings.volume = this.tbarVolume.Value;      //改變音量大小
        }

//音量打下++
        private void button9_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.settings.volume += 1;       //音量大小+1
            int volume = this.axWindowsMediaPlayer1.settings.volume;
            this.tbarVolume.Value = volume;
        }

//音量大小--
        private void button10_Click(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.settings.volume -= 1;       //音量大小-1
            int volume = this.axWindowsMediaPlayer1.settings.volume;
            this.tbarVolume.Value = volume;
        }

//播放位置
        private void tbarPlayLoaction_Scroll(object sender, EventArgs e)
        {
            this.axWindowsMediaPlayer1.Ctlcontrols.currentPosition = tbarPlayLoaction.Value;
        }

//循环播放
        private void loopToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.loopToolStripMenuItem.Checked)
            {
                ////第一种:
                //if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped)
                //{
                //    axWindowsMediaPlayer1.Ctlcontrols.play();
                //}

////第二种:
                axWindowsMediaPlayer1.settings.setMode("loop", true);
            }
        }

}
}

C# axWindowsMediaPlayer制作播放器的更多相关文章

  1. 原生js制作播放器

    以前 就想做一个播放器,一直没狠下心来,今天终于狠下心来,把这个做出来了(因为有点无聊) 做这个播放器  也百度了一下, 你叫我做,我肯定做不出来, 就算用jquery  我也做不出来. 以前也用过a ...

  2. 使用react native制作的一款网络音乐播放器

    使用react native制作的一款网络音乐播放器 基于第三方库 react-native-video设计"react-native-video": "^1.0.0&q ...

  3. QT制作一个图片播放器

    前言:使用qt制作了一个简单的图片播放器,可以播放gif.png等格式图片 先来看看播放器的功能(当然是很简陋的,没有很深入的设计): 1.点击图片列表中图片进行播放. 2.自动播放,播放的图片的间隔 ...

  4. JavaCV 学习(二):使用 JavaCV + FFmpeg 制作拉流播放器

    一.前言 在 Android 音视频开发学习思路 中,我们不断的学习和了解音视频相关的知识,随着知识点不断的学习,我们现在应该做的事情,就是将知识点不断的串联起来.这样才能得到更深层次的领悟.通过整理 ...

  5. HTML+纯JS制作音乐播放器

    该篇文章会教你通过JavaScript制作一个简单的音乐播放器.包括播放.暂停.上一曲和下一曲. 阅读本文章你需要对HTML.CSS和Javascript有基本的了解. 话不多说,先上图. emmm. ...

  6. 使用 原生js 制作插件 (javaScript音乐播放器)

    1.引用页面 index.html <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  7. 使用AVPlayer制作一个播放器

    代码地址如下:http://www.demodashi.com/demo/11685.html AVPlayer 是一个强大的视频播放器,可以播放多种格式的视频,缺点是没有控制界面,需要自己去实现. ...

  8. Swift - 制作一个在线流媒体音乐播放器(使用StreamingKit库)

    在之前的文章中,我介绍了如何使用 AVPlayer 制作一个简单的音乐播放器(点击查看1.点击查看2).虽然这个播放器也可以播放网络音频,但其实际上是将音频文件下载到本地后再播放的. 本文演示如何使用 ...

  9. 使用LM386制作Arduino音乐播放器

    在我们的项目中添加声音或音乐总是会使其看起来更酷一些,听上去更有吸引力.特别是如果您使用的是Arduino开发板,并且有很多空余的引脚,只需要添加一个SD卡模块和一个普通的扬声器即可轻松添加音效.在本 ...

随机推荐

  1. css3的counter的用法

    很早之前,计数器仅存在于ul,ol等元素中,如何想给其他元素增加计数,就只能通过list-style-image,或者background-image来实现.不过现在css3增加了counter属性, ...

  2. sql 先查出已知的数据或者需要的数据再筛选

    sql 先查出已知的数据或者需要的数据再筛选

  3. BZOJ4481 JSOI2015非诚勿扰(概率期望+树状数组)

    首先求出每个女性接受某个男性的概率.这个概率显然是一个无穷等比数列求和. 然后按编号从小到大考虑每个女性,维护出每个男性被选择的期望次数,BIT上查询后缀和即可. 需要long double. #in ...

  4. BZOJ4602: [Sdoi2016]齿轮 DFS 逆元

    这道题就是一个DFS,有一篇奶牛题几乎一样.但是这道题卡精度. 这道题网上的另一篇题解是有问题的.取对数这种方法可以被轻松卡.比如1e18 与 (1e9-1)*(1e9+1)取对数根本无法保证不被卡精 ...

  5. poj 1201 TYVJ 1415 Intervals

    Description: 给定n个闭区间[ai,bi] 和n个整数ci,你需要构造一个集合Z,使得对于任何的i∈[1,n],Z中满足x∈[ai,bi]的x不少于ci个 求这样的整数集合Z至少包含多少个 ...

  6. CMU Bomblab 答案

    室友拉我做的... http://csapp.cs.cmu.edu/3e/labs.html Border relations with Canada have never been better. ...

  7. sqrti128

    求平方根下取整,对于gcc type __uint128_t. ~45.5ns/op on i7-7700k@4.35G,即typical <200cyc/op. Together with u ...

  8. mycat 管理MySQL5.7主从搭建

    1.首先安装MySQL ab: 192.168.6.163 master 192.168.6.167 slave master: vi /etc/opt/rh/rh-mysql57/my.cnf.d/ ...

  9. 7月16号day8总结

    今天学习过程和小结 1.列举Linux常用命令 shutdown now Linux关机 rebot重启 mkdir mkdir -p递归创建 vi/touth filename rm -r file ...

  10. python异常之with

    1.基本语法 with expression [as target]: with_body 参数说明: expression:是一个需要执行的表达式: target:是一个变量或者元组,存储的是exp ...