模仿迅L看看<音频播放器> 实现点击进度条,跳转播放
<Style x:Key="btnFallback" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="bd" Height="50" Width="50" Background="Transparent" CornerRadius="36" BorderBrush="Gray" BorderThickness="2"> <Path x:Name="p1" Data="M576 160v320l320-320v704l-320-320v320l-352-352z" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Top="10" Fill="Gray" Height="30" Stretch="Fill" Width="30" Canvas.Left="0" Margin="0 0 5 0"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="bd" Value="white"/> <Setter Property="Fill" TargetName="p1" Value="white"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="btnPlay" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="bd" Height="60" Width="60" Background="Transparent" CornerRadius="36" BorderBrush="Gray" BorderThickness="2"> <Path x:Name="p1" Data="M790.857 529.714l-758.857 421.714q-13.143 7.429-22.571 1.714t-9.429-20.571v-841.143q0-14.857 9.429-20.571t22.571 1.714l758.857 421.714q13.143 7.429 13.143 17.714t-13.143 17.714z" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Top="10" Fill="Gray" Height="30" Stretch="Fill" Width="30" Canvas.Left="0" Margin="10 0 5 0"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="bd" Value="white"/> <Setter Property="Fill" TargetName="p1" Value="white"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="btnStop" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="bd" Height="60" Width="60" Background="Transparent" CornerRadius="36" BorderBrush="Gray" BorderThickness="2"> <Path x:Name="p1" Data="M877.714 109.714v804.571q0 14.857-10.857 25.714t-25.714 10.857h-292.571q-14.857 0-25.714-10.857t-10.857-25.714v-804.571q0-14.857 10.857-25.714t25.714-10.857h292.571q14.857 0 25.714 10.857t10.857 25.714zM365.714 109.714v804.571q0 14.857-10.857 25.714t-25.714 10.857h-292.571q-14.857 0-25.714-10.857t-10.857-25.714v-804.571q0-14.857 10.857-25.714t25.714-10.857h292.571q14.857 0 25.714 10.857t10.857 25.714z" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Top="10" Fill="Gray" Height="30" Stretch="Fill" Width="30" Canvas.Left="0" Margin="5 0 5 0"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="bd" Value="white"/> <Setter Property="Fill" TargetName="p1" Value="white"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="btnFast" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="bd" Height="50" Width="50" Background="Transparent" CornerRadius="36" BorderBrush="Gray" BorderThickness="2"> <Path x:Name="p1" Data="M25.714 943.429q-10.857 10.857-18.286 7.429t-7.429-18.286v-841.143q0-14.857 7.429-18.286t18.286 7.429l405.714 405.714q4.571 4.571 7.429 10.857v-405.714q0-14.857 7.429-18.286t18.286 7.429l405.714 405.714q10.857 10.857 10.857 25.714t-10.857 25.714l-405.714 405.714q-10.857 10.857-18.286 7.429t-7.429-18.286v-405.714q-2.857 5.714-7.429 10.857z" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Top="10" Fill="Gray" Height="30" Stretch="Fill" Width="30" Canvas.Left="0" Margin="6 0 0 0"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="bd" Value="white"/> <Setter Property="Fill" TargetName="p1" Value="white"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="btnOpen" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="bd" Height="60" Width="160" Background="Transparent" CornerRadius="3" BorderBrush="Gray" BorderThickness="2"> <StackPanel Orientation="Horizontal" Margin="30 0 0 0"> <Path x:Name="p1" Data="M1073.714 544q0 17.714-17.714 37.714l-192 226.286q-24.571 29.143-68.857 49.429t-82 20.286h-621.714q-19.429 0-34.571-7.429t-15.143-24.571q0-17.714 17.714-37.714l192-226.286q24.571-29.143 68.857-49.429t82-20.286h621.714q19.429 0 34.571 7.429t15.143 24.571zM877.714 347.429v91.429h-475.429q-53.714 0-112.571 27.143t-93.714 68.286l-195.429 229.714q0-2.286-0.286-7.143t-0.286-7.143v-548.571q0-52.571 37.714-90.286t90.286-37.714h182.857q52.571 0 90.286 37.714t37.714 90.286v18.286h310.857q52.571 0 90.286 37.714t37.714 90.286z" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Top="10" Fill="Gray" Height="30" Stretch="Fill" Width="30" Canvas.Left="0" Margin="0 0 5 0"/> <TextBlock Text="打开文件..." Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="BorderBrush" TargetName="bd" Value="white"/> <Setter Property="Fill" TargetName="p1" Value="white"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Grid> <Grid Margin="2"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="90"/> </Grid.RowDefinitions> <MediaElement x:Name="MePack" Grid.RowSpan="2" MediaOpened="MePack_MediaOpened" LoadedBehavior="Manual"/> <Border x:Name="bdMain" Grid.RowSpan="2" Background="#161D27"> <Button Style="{StaticResource btnOpen}" Click="openBtn_Click"/> </Border> <Grid Grid.Row="2" Height="80" Background="Black" Opacity=".8"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="20"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Slider x:Name="CvSlider" Grid.ColumnSpan="5" Style="{StaticResource SliderEnter}" PreviewMouseLeftButtonDown="CvSlider_PreviewMouseLeftButtonDown" PreviewMouseLeftButtonUp="CvSlider_PreviewMouseLeftButtonUp" ValueChanged="CvSlider_ValueChanged" Maximum="0" IsMoveToPointEnabled="True"/> <Button x:Name="btnBack" Grid.Row="1" Grid.Column="1" Style="{StaticResource btnFallback}" Margin="10 5" HorizontalAlignment="Center" VerticalAlignment="Center"/> <Button x:Name="btnPlay" Grid.Row="1" Grid.Column="2" Style="{StaticResource btnPlay}" Margin="10 0" HorizontalAlignment="Center" VerticalAlignment="Center" Click="btnSwitch" Tag="0" ToolTip="播放"/> <Button x:Name="btnStop" Grid.Row="1" Grid.Column="2" Visibility="Hidden" Style="{StaticResource btnStop}" Margin="10 0" HorizontalAlignment="Center" VerticalAlignment="Center" Click="btnSwitch" Tag="1" ToolTip="暂停"/> <Button x:Name="btnFast" Grid.Row="1" Grid.Column="3" Style="{StaticResource btnFast}" Margin="10 5" HorizontalAlignment="Center" VerticalAlignment="Center"/> <TextBlock x:Name="TimeLengh" Text="00:00:00" Margin="10" Grid.Column="4" Grid.Row="1" HorizontalAlignment="Right"/> </Grid> </Grid> </Grid>
public DispatcherTimer tm = new DispatcherTimer(); public TimeSpan ts = new TimeSpan(); ; public MediaElementMain() { InitializeComponent(); tm.Tick += tm_Tick; tm.Interval = TimeSpan.FromSeconds(0.05); tm.Start(); } void tm_Tick(object sender, EventArgs e) { ) { this.CvSlider.Value = MePack.Position.TotalSeconds; ;//时 ; ;//分 ;//秒 ;//时 ; ;//分 ;//秒 TimeLengh.Text = d.ToString() + ":" + f.ToString() + ":" + w.ToString() + "/" + o.ToString() + ":" + k.ToString() + ":" + l.ToString(); } } private void openBtn_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "ir files (*.wmv)||*.avi||*.mp3||*.mp4||All files (*.*)|*.*"; //过滤文件类型 if (openFile.ShowDialog() == true) { MePack.Source = new Uri(openFile.FileName,UriKind.Relative); MePack.Play(); bdMain.Visibility = Visibility.Hidden; btnStop.Visibility = Visibility.Visible; btnPlay.Visibility = Visibility.Hidden; //getTime(openFile.FileName); } } //public static string getTime(string path) //{ // try // { // Shell32.Shell shell = new Shell32.ShellClass(); // //文件路径 // Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\"))); // //文件名称 // Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 2)); // return folder.GetDetailsOf(folderitem, 21); // } // catch (Exception ex) // { // return null; // } //} private void MePack_MediaOpened(object sender, RoutedEventArgs e) { btnSwitch(btnPlay, null); CvSlider.Minimum = ; CvSlider.Maximum = MePack.NaturalDuration.TimeSpan.TotalSeconds; TimeSpan totaotp = MePack.NaturalDuration.TimeSpan; } private void btnSwitch(object sender, RoutedEventArgs e) { if (MePack.Source != null) { Button btn = sender as Button; int num = Convert.ToInt32(btn.Tag); ) { MePack.Pause(); btnStop.Visibility = Visibility.Hidden; btnPlay.Visibility = Visibility.Visible; } else { MePack.Play(); btnStop.Visibility = Visibility.Visible; btnPlay.Visibility = Visibility.Hidden; } } } private void CvSlider_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { begin = ; } private void CvSlider_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { MePack.Position = ts; ;//时 ; ;//分 ;//秒 ;//时 ; ;//分 ;//秒 TimeLengh.Text = d.ToString() + ":" + f.ToString() + ":" + w.ToString() + "/" + o.ToString() + ":" + k.ToString() + ":" + l.ToString(); begin = (int)ts.TotalSeconds; } private void CvSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) { ts = TimeSpan.FromSeconds(e.NewValue); ;//时 ; ;//分 ;//秒 ;//时 ; ;//分 ;//秒 TimeLengh.Text = d.ToString() + ":" + f.ToString() + ":" + w.ToString() + "/" + o.ToString() + ":" + k.ToString() + ":" + l.ToString(); }
效果图:
http://www.cnblogs.com/yanjinhua/p/5643459.html
模仿迅L看看<音频播放器> 实现点击进度条,跳转播放的更多相关文章
- 阿里播放器踩坑记录 进度条重构 video loadByUrl失效解决方案
如果本文对你有用,请爱心点个赞,提高排名,帮助更多的人.谢谢大家!❤ 如果解决不了,可以在文末进群交流. 文档地址:https://player.alicdn.com/aliplayer/index. ...
- html5 vedio 播放器,禁掉进度条快进快退事件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ckplayer,超酷网页播放器,用于集成在网站中的播放器
自己在工作中做了一个教学网站,点击左边课程,右边播放视频,经过源代码分析,用的就是这个播放器 网址:http://www.ckplayer.com/ 具体使用播放器网站上说的比较明白 div id=& ...
- 腾讯X5内核使用详解(X5内核播放器使用如何去除控制栏全屏播放)以及一些注意事项
例子下载地址 https://www.lanzous.com/i2zsv5g GIT就不用了麻烦的不行 本人安卓刚学 就上X5内核弄了老长时间由于对maven 和idea不熟悉刚开始导包都是 ...
- Android——音乐播放器完善——进度条显示当前播放进度,加可拖动进度条(未待解决完问题)
效果: 问题:可拖动进度条随进度条移动时,会致使音乐卡顿(待解决) xml <?xml version="1.0" encoding="utf-8"?&g ...
- 从零开始学 Web 之 HTML5(四)拖拽接口,Web存储,自定义播放器
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...
- Java利用VLC开发简易视屏播放器
1.环境配置 (1)下载VLC VlC官网http://www.videolan.org/ 各个版本的下载地址http://download.videolan.org/pub/videolan ...
- 如何用vue打造一个移动端音乐播放器
写在前面 没错,这就是慕课网上的那个vue音乐播放器,后台是某音乐播放器的线上接口扒取,虽然这类项目写的人很多,但不得不说这还是个少有的适合vue提升的好项目,做这个项目除了想写一个比较大并且功能复杂 ...
- iOS开发拓展篇—音频处理(音乐播放器3)
iOS开发拓展篇—音频处理(音乐播放器3) 说明:这篇文章主要介绍音频工具类和播放工具类的封装. 一.控制器间数据传递 1.两个控制器之间数据的传递 第一种方法:self.parentViewCont ...
随机推荐
- 从天猫和支付宝身上学习opcity与rgba
不知道什么时候,一个双层透明的对话框悄然流行了起来. 我们在各大网站上都能见到类似这样的对话框: 这样的聚焦更明显,用户体验更好,也显得更加的高大上. 先说点题外话,这种布局如何用CSS+DIV去实现 ...
- 辛巴学院-Unity-剑英陪你零基础学c#系列(三)计算与类型
辛巴学院:正大光明的不务正业. 中秋节快乐,每逢佳节倍思亲,尤其是那素未谋面的老婆,对吧,屌丝们. 今天我们来探索一下C#里面奇怪的计算,奇怪的类型. 奇怪的计算 当我刚刚接触计算机编程的时候,一 ...
- 开源WinForms界面开发框架Management Studio 选项卡文档 插件 Office 2007蓝色风格 后台线程
Management Studio是我在WinForms小项目开发过程中搭建起来的一个插件式结构的应用程序框架,因为简单灵活又容易扩展,现在将它开源供读者参考. 跑起来的效果图如下所示,具备选项卡式多 ...
- CSS系列:CSS中盒子模型
盒子模型是CSS控制页面时一个很重要的概念.所有页面中的元素都可以看成是一个盒子,占据着一定的页面空间.可以通过调整盒子的边框和距离等参数,来调节盒子的位置和大小. 1. 盒子的内部结构 在CSS中, ...
- 前端MVVM框架avalon揭秘 - HTML编译器
MVVM试图更加清晰的讲用户界面(UI)开发从应用程序的业务逻辑与行为中心分离,因为,很多这样的模式的实现都需要利用声明式数据绑定来实现讲View(视图)工作从其他层分离 所以出现了一大堆自定义的声明 ...
- Unity3D移植到Windows phone8 遇到的点点滴滴
LitJson.JsonMapper:Type.GetInterface(String)=>Type.GetInterface(String,Boolean) protobuf应位于Assets ...
- SQL 里解析 XML 格式 字段 信息
DECLARE @ItemMessage XML ),zje ),yfje ),bcje ),URL ),Remark )) SET @ItemMessage=N'<List> <i ...
- 谈谈基于OAuth 2.0的第三方认证 [中篇]
虽然我们在<上篇>分别讨论了4种预定义的Authorization Grant类型以及它们各自的适用场景的获取Access Token的方式,我想很多之前没有接触过OAuth 2.0的读者 ...
- PinnedHeaderListView实现删除
项目中用到四个List集合展示一个页面,并且每个页面都会有一个标题栏.找了半天资料决定用PinnedHeaderListView开源项目.最后需求又来了,需要一个删除的功能,又去网上找资料,发现没有实 ...
- Lua 学习笔记(六)迭代器
一.迭代器的定义 “迭代器”就是一种可以遍历一种集合中所有元素的机制.在Lua中迭代器以函数的形式表示,即没掉用一次函数,即可返回集合中的“下一个”元素.迭代器的实现可以借助于闭合函数实现, ...