在C#中开放视频播放器示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void ADDMEDIA_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.AddExtension = true;
open.DefaultExt = "*.*";
open.Filter = "Media(*.*)|*.*";
open.ShowDialog();
mediaElement1.MediaOpened += new RoutedEventHandler(mediaElement1_MediaOpened);
mediaElement1.Source = new Uri(open.FileName);
}
private void Play_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Play();
}
private void PAUSE_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Pause();
}
private void STOP_Click(object sender, RoutedEventArgs e)
{
mediaElement1.Stop();
}
void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
{
//label1.Content = mediaElement1.Source.ToString();
}
}
}
在C#中 开发一个视频播放器非常简单。
首先,我们必须打开一个新的WPF窗口表单,从工具箱中拖放媒体元素和四个按钮用于播放,暂停,停止,添加视频。
然后编写代码,(双击任一个按钮,进入代码模式)如下所示
日期:2020-04-11 22:50:33 来源:oir作者:oir
