一、前言

对于<MediaElement>前两章介绍了差不多了,其实好的界面还需要UI工程师的配合,比如帮忙设计下按钮的样式等等。同样视频本身也需要吸引人,不然做的再好的播放器也没用。之后,我对代码进行了下小修改,粒子特效那部分就不再放了。

二、代码

前台代码

 <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPF_Nav"
xmlns:dxlc="http://schemas.devexpress.com/winfx/2008/xaml/layoutcontrol" xmlns:dxwui="http://schemas.devexpress.com/winfx/2008/xaml/windowsui" x:Class="WPF_Nav.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="" Width="" WindowStyle="None" ResizeMode="NoResize" WindowStartupLocation ="CenterScreen" Loaded="Window_Loaded"> <Window.Resources>
<LinearGradientBrush x:Key="SliderBackground" StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.5" Color="#00b3fe"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="SliderThumb" StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="" Color="#FFD9D3E8"/>
</LinearGradientBrush> <Style x:Key="Slider_RepeatButton" TargetType="RepeatButton">
<Setter Property="Focusable" Value="false" />
<Setter Property="Height" Value=""/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border Background="{StaticResource SliderBackground}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="Slider_RepeatButton1" TargetType="RepeatButton">
<Setter Property="Focusable" Value="false" />
<Setter Property="Height" Value=""/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RepeatButton">
<Border Background="Silver" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="Slider_Thumb" TargetType="Thumb">
<Setter Property="Focusable" Value="false" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Ellipse Name="e" Width="" Height="" Fill="White" Stroke="Gray"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style TargetType="Slider">
<Setter Property="Focusable" Value="false" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Slider">
<Grid>
<Border BorderBrush="Red" BorderThickness="" CornerRadius="0,0,0,0">
<Track Name="PART_Track">
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource Slider_RepeatButton}" Command="Slider.DecreaseLarge"/>
</Track.DecreaseRepeatButton>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource Slider_RepeatButton1}" Command="Slider.IncreaseLarge"/>
</Track.IncreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource Slider_Thumb}"/>
</Track.Thumb>
</Track>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="Button_Close" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Image x:Name="IMG" Source="Resources\images\cancel.png"></Image>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="IMG" Property="Source" Value="Resources\images\cancel_hover.png"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="Button_Left" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Image x:Name="IMG" Source="Resources\images\left.png" Stretch="Fill"></Image>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="IMG" Property="Source" Value="Resources\images\left_hover.png"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="Button_Right" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Image x:Name="IMG" Source="Resources\images\right.png" Stretch="Fill"></Image>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="IMG" Property="Source" Value="Resources\images\right_hover.png"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> </Window.Resources> <Grid Name="Main_Grid" MouseLeftButtonDown="Main_Drag">
<Grid.RowDefinitions>
<RowDefinition Height=""></RowDefinition>
<RowDefinition Height=""></RowDefinition>
<RowDefinition Height=""></RowDefinition>
</Grid.RowDefinitions> <Border Name="title_Border" BorderBrush="#FBD3D0CD" BorderThickness="" Grid.Row="">
<Grid Name="Title">
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""></ColumnDefinition>
<ColumnDefinition Width=""></ColumnDefinition>
<ColumnDefinition Width=""></ColumnDefinition>
<ColumnDefinition Width=""></ColumnDefinition>
</Grid.ColumnDefinitions> <Grid Grid.Column="">
<Image Source="Resources\images\logo.png" Stretch="Uniform" Margin="10,0,20,0" ></Image>
</Grid>
<Grid Grid.Column="">
<Canvas x:Name="ParticleHost" Width="" >
<TextBlock Name="txtB_Step" Grid.Column="" Width="" Height="" TextAlignment="Center" FontSize="" FontFamily="Microsoft YaHei" Margin="100,7,0,0" ToolTip="左键单击视频—播放/暂停"/>
</Canvas>
</Grid> <Button Name="btn_Close" Grid.Column="" Width="" Click="Close_Click" Margin="37,10,13,12" HorizontalAlignment="Center" Focusable="False" Style="{StaticResource Button_Close}" RenderTransformOrigin="0.5,0.5" ToolTipService.ToolTip="关闭视频" ToolTipService.InitialShowDelay="" ToolTipService.Placement="Bottom">
<Button.RenderTransform>
<RotateTransform x:Name="trans" Angle=""/>
</Button.RenderTransform>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard >
<Storyboard>
<DoubleAnimation From="" To="" Duration="0:0:0.4"
Storyboard.TargetName="trans"
Storyboard.TargetProperty="Angle"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button> </Grid>
</Border> <Grid Name="Movie" Grid.Row="" MouseEnter="QS_Movie_Enter" MouseLeave="QS_Movie_Leave">
<MediaElement Stretch="Fill" LoadedBehavior="Manual" Name="QS_Movie" MediaOpened="Element_MediaOpened" Loaded="QS_Movie_Loaded" MouseLeftButtonDown="QS_Movie_MouseLeftButtonDown"/>
<Button Name="btn_pre" Width="" Height="" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Left_Click" Focusable="False" Style="{StaticResource Button_Left}"/>
<Button Name="btn_next" Width="" Height="" HorizontalAlignment="Right" VerticalAlignment="Center" Click="Right_Click" Focusable="False" Style="{StaticResource Button_Right}"/>
</Grid> <Border Name="Progress_Border" BorderBrush="#FBD3D0CD" BorderThickness="" Grid.Row="">
<Grid Name="Control_Progress" Margin="3,3,-3,-3" >
<Grid >
<Slider Grid.Column="" Name="timelineSlider" VerticalAlignment="Center" PreviewMouseLeftButtonDown="timelineMDown" PreviewMouseLeftButtonUp="timelineMUp" BorderThickness="0,6,0,0" Height="" Margin="49,10,49,16" />
</Grid>
</Grid>
</Border>
</Grid>
</Window>

    

后台代码依然是老一套,就小修了一下下:

  public partial class MainWindow : Window
{
DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); // 定义一个DT
bool play_flag = true; //判断播放状态
int play_now = ; //判断当前视频索引
int play_target;
List<string> Play_Video = new List<string>();
List<string> Title_Video = new List<string>(); public MainWindow()
{
InitializeComponent();
Play_Video = LoadMovies();
Title_Video = LoadTitles();
} private List<string> LoadTitles()
{
List<string> list_title = new List<string>();
list_title.Add("isBIM 算量简介");
return list_title;
}
private List<string> LoadMovies()
{
List<string> Movie_Uri = new List<string>();
Movie_Uri.Add("Resources/videos/QS_Intro.mp4");
return Movie_Uri;
} private void Play_Click(object sender, RoutedEventArgs e)
{
QS_Movie.Play();
} private void Pause_Click(object sender, RoutedEventArgs e)
{
QS_Movie.Pause();
} private void Element_MediaOpened(object sender, EventArgs e)
{
timelineSlider.Maximum = QS_Movie.NaturalDuration.TimeSpan.TotalMilliseconds; //设置slider最大值
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); //超过计时间隔时发生
dispatcherTimer.Interval = new TimeSpan(, , , , ); //DT间隔
dispatcherTimer.Start(); //DT启动
} private void dispatcherTimer_Tick(object sender, EventArgs e)
{
int time = (int)QS_Movie.Position.TotalSeconds;
timelineSlider.ToolTip = SecToTime(time);
timelineSlider.Value = QS_Movie.Position.TotalMilliseconds; //slider滑动值随播放内容位置变化
} private string SecToTime(int sec)
{
int min = sec / ;
sec = sec - min * ;
int hour = min / ;
min = min - hour * ;
string h = hour.ToString();
string mm = ((min < ) ? "" : "") + min.ToString();
string ss = ((sec < ) ? "" : "") + sec.ToString();
string time = h + ":" + mm + ":" + ss;
return time;
}
private void timelineMDown(object sender, EventArgs e)
{
dispatcherTimer.Stop();
}
private void timelineMUp(object sender, EventArgs e)
{
QS_Movie.Position = new TimeSpan(, , , , (int)timelineSlider.Value);
dispatcherTimer.Start();
QS_Movie.Play();
} private void QS_Movie_Loaded(object sender, RoutedEventArgs e)
{
QS_Movie.Source = new Uri(Play_Video[], UriKind.Relative);
QS_Movie.Play();
txtB_Step.Text = Title_Video[];
} private void Left_Click(object sender, RoutedEventArgs e)
{
play_target = (play_now + Play_Video.Count-) % Play_Video.Count;
PreLoad(, play_target);
play_now = play_target;
} private void Right_Click(object sender, RoutedEventArgs e)
{
play_target = (play_now + ) % Play_Video.Count;
PreLoad(, play_target);
play_now = play_target;
} private void PreLoad(int interval, int index)
{
QS_Movie.Source = new Uri(Play_Video[index],UriKind.Relative);
QS_Movie.Play();
System.Threading.Thread.Sleep(interval);
QS_Movie.Pause();
txtB_Step.Text = Title_Video[index];
} private void QS_Movie_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{ if(play_flag==true)
{
QS_Movie.Play();
}
if(play_flag==false)
{
QS_Movie.Pause();
}
play_flag = !play_flag;
} private void Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Main_Drag(object sender, MouseButtonEventArgs e)
{
this.DragMove();
} private void QS_Movie_Enter(object sender, MouseEventArgs e)
{
btn_pre.Visibility = System.Windows.Visibility.Visible;
btn_next.Visibility = System.Windows.Visibility.Visible;
}
private void QS_Movie_Leave(object sender, MouseEventArgs e)
{
btn_pre.Visibility = System.Windows.Visibility.Hidden;
btn_next.Visibility = System.Windows.Visibility.Hidden;
}
}

三、效果图

GIF录制工具用的GifCam,一搜就能搜到,就是录不到鼠标??!!

【MediaElement】WPF视频播放器【3】的更多相关文章

  1. 基于<MediaElement>的WPF视频播放器(可拖拽进度条播放)【1】

    一.前言       前两天上峰要求做一个软件使用向导,使用WPF制作.这不,这两天从一张白纸开始学起,做一个播放演示视频的使用向导.以下是粗设计的原型代码: 二.效果图 三.代码 前台代码: < ...

  2. 【MediaElement】WPF视频播放器【1】

    一.前言       前两天上峰要求做一个软件使用向导,使用WPF制作.这不,这两天从一张白纸开始学起,做一个播放演示视频的使用向导.以下是粗设计的原型代码: 二.效果图 三.代码 前台代码: < ...

  3. 基于<MediaElement>的WPF视频播放器(终章)【3】

    一.前言 对于<MediaElement>前两章介绍了差不多了,其实好的界面还需要UI工程师的配合,比如帮忙设计下按钮的样式等等.同样视频本身也需要吸引人,不然做的再好的播放器也没用.之后 ...

  4. 基于<MediaElement>的WPF视频播放器(带部分特效)【2】

    一.前言       上回说到需要做放视频的使用向导,这两天公司里的老司机一直帮我答疑解惑,让这个任务变得挺顺的,真心感谢他们! 这次与[1]中的不同之处在于: (1)播放和暂停按钮集成在<Me ...

  5. 【MediaElement】WPF视频播放器【2】

    一.前言       上回说到需要做放视频的使用向导,这两天公司里的老司机一直帮我答疑解惑,让这个任务变得挺顺的,真心感谢他们! 这次与[1]中的不同之处在于: (1)播放和暂停按钮集成在<Me ...

  6. 封装:WPF基于MediaElement封装的视频播放器

    原文:封装:WPF基于MediaElement封装的视频播放器 一.目的:应用MediaElement创建媒体播放器 二.效果图 三.目前支持功能 播放.暂停.停止.快进.快退.声音大小.添加播放列表 ...

  7. WPF技术触屏上的应用系列(三): 视频播放器的使用及视频播放、播放、暂停、可拖动播放进度效果实现

    原文:WPF技术触屏上的应用系列(三): 视频播放器的使用及视频播放.播放.暂停.可拖动播放进度效果实现 去年某客户单位要做个大屏触屏应用,要对档案资源进行展示之用.客户端是Window7操作系统,5 ...

  8. 在C#中实现视频播放器

    当我们需要在C#中实现视频播放器的时候,可以使用如下几种方法: 一.使用MediaPlayer ActiveX控件 在C#中支持视屏播放器最简单的方式就是插入MediaPlayer控件了,在WPF中还 ...

  9. WPF播放器

    最近由于工作需要,需要做一个播放软件,在网上参考了很多例子,园子里有很多代码.其中最多的就是wpf自带的MediaElement控件,或者VLC视频播放器. 先附我自己查询资料的链接: MediaEm ...

随机推荐

  1. Yii 2.0 使用验证码

    Yii2.0 提供了验证码组件.调用起来比较方便.以登录页面添加验证码为例. 1. 模型中添加字段和验证规则. common\models\LoginForm 添加如下代码 public $captc ...

  2. Sqlserver新增自增列

    if exists(select * from syscolumns where id=object_id('表名') and name='列名') begin alter table 表名 drop ...

  3. nexus实现从windows迁移至Linux平台

    说明: 由于老环境是在本地windows 2008 R2里面搭建的nexus,前面搭建了jenkins,需要将maven私库迁移至云服务器的CentOS 7系统下,之前没做过nexus的迁移,在网上看 ...

  4. OpenWrt架设nginx php网站

    参考 http://www.vinoca.org/2012/05/31/openwrt%E6%9E%B6%E8%AE%BEnginxphp%E7%BD%91%E7%AB%99/ 一.安装相关包 opk ...

  5. IDEA 创建Spring Boot 项目

    一.准备环境 配置Maven,打开设置页面File - Setting,快捷键Ctrl + Alt + S,找到Maven,默认是IDEA 自带的插件,User setting file 配置文件默认 ...

  6. mtv网站架构模式适合企业网站应用吗?

    mtv网站架构模式适合企业网站应用吗?有时候在思考这样一个问题. 从开发角度来说,本来mvc的进度慢了些,如果在数据库管理方面用sql的话,管理起来也不很方便.小企业网本来数据就不很多,也没什么太多安 ...

  7. Powershell按文件最后修改时间删除多余文件

    Powershell按文件最后修改时间删除多余文件 1. 删除目录内多余文件,目录文件个数大于$count后,按最后修改时间倒序排列,删除最旧的文件. Sort-Object -Property La ...

  8. ASP.NET 异步Web API + jQuery Ajax 文件上传代码小析

    该示例中实际上应用了 jquery ajax(web client) + async web api 双异步. jquery ajax post $.ajax({ type: "POST&q ...

  9. mac react-native从零开始android真机测试

    1. 安装android相关jdk,(https://blog.csdn.net/vvv_110/article/details/72897142) 2. 手机和mac使用usb连接, 手机开发者设置 ...

  10. 哈夫曼(Huffman)树+哈夫曼编码

    前天acm实验课,老师教了几种排序,抓的一套题上有一个哈夫曼树的题,正好之前离散数学也讲过哈夫曼树,这里我就结合课本,整理一篇关于哈夫曼树的博客. 主要摘自https://www.cnblogs.co ...