zoukankan      html  css  js  c++  java
  • C#使用WindowsMediaPlayer实现视频播放

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Windows.Forms.DataVisualization.Charting;

    namespace WindowsFormsApplication2
    {


    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    string playPath = null;
    string directory = null;
    List<string> playArray = null;
    private void 打开文件ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    using (OpenFileDialog openFileDialog = new OpenFileDialog())
    {
    openFileDialog.Filter = "mp4|*.mp4|视频文件(*.avi;*.wmv)|(*.avi;*.wmv)|All File(*.*)|(*.*)";
    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
    playPath = openFileDialog.FileName;
    directory = Path.GetDirectoryName(playPath);

    playArray = Form1.GetplayCollection(directory);

    }
    axWindowsMediaPlayer1.URL = playPath;

    }
    }

    public static List<string> GetplayCollection(string path)
    {
    string[] playarray = Directory.GetFiles(path);
    var result = from playstring in playarray
    where playstring.EndsWith("wmv", StringComparison.OrdinalIgnoreCase) ||
    playstring.EndsWith("avi", StringComparison.OrdinalIgnoreCase)||
    playstring.EndsWith("mp4", StringComparison.OrdinalIgnoreCase)
    select playstring;
    return result.ToList();
    }

    private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    Application.Exit();
    }

    private void 播放暂停ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    if ((int)axWindowsMediaPlayer1.playState == 2)
    axWindowsMediaPlayer1.Ctlcontrols.play();
    else if ((int)axWindowsMediaPlayer1.playState == 3)
    axWindowsMediaPlayer1.Ctlcontrols.pause();
    }

    private void 停止ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    axWindowsMediaPlayer1.Ctlcontrols.pause();
    }

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

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

    private void 上一曲ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    axWindowsMediaPlayer1.Ctlcontrols.previous();
    }

    private void 下一曲ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    axWindowsMediaPlayer1.Ctlcontrols.next();
    }

    private void 升高音量ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    if (axWindowsMediaPlayer1.settings.volume <= 90)
    {
    axWindowsMediaPlayer1.settings.volume += 10;
    }
    else
    {
    axWindowsMediaPlayer1.settings.volume = 100;
    }
    }

    private void 降低音量ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    if (axWindowsMediaPlayer1.settings.volume >= 10)
    {
    axWindowsMediaPlayer1.settings.volume -= 10;
    }
    else
    {
    axWindowsMediaPlayer1.settings.volume = 0;
    }
    }

    private void 静音ToolStripMenuItem_Click(object sender, EventArgs e)
    {
    axWindowsMediaPlayer1.settings.volume = 0;
    }
    }
    }

    111
  • 相关阅读:
    高精度模板_C++
    NOIP总结
    HDU2063_过山车_C++
    手写堆_C++
    NOIP2013Day1解题报告
    [ CodeVS冲杯之路 ] P1368
    POJ1002_487-3279_C++
    [ CodeVS冲杯之路 ] P1092
    POJ2376_Cleaning Shifts_C++
    欧几里得距离_曼哈顿距离_切比雪夫距离
  • 原文地址:https://www.cnblogs.com/zwj-199306231519/p/10614693.html
Copyright © 2011-2022 走看看