WPF视频播放器自做
WPF MediElement实现视频播放

WPF MediElement实现视频播放WPF中可以使用MediaElement控件来进行音视频播放,然后需要做个进度条啥的,但是MediaElement.Position(进度)和MediaElement.NaturalDuration居然都不是依赖属性,简直不能忍!好吧,首先说说比较传统的做法(winform?)slider用来显示进度以及调整进度,tb1显示当前进度的时间值,tb2显示视频的时常。
player_Loaded 事件中使用DispatcherTimer来定时器获取当前视频的播放进度,player_MediaOpened 事件中获取当前视频的时长(只有在视频加载完成后才可以获取到)slider_ValueChanged 事件中执行对视频进度的调整xaml: <MediaElement Name="player"Source="e:\MVVMLight (1).wmv" Loaded="player_Loaded" MediaOpened="player_MediaOpened"/><Slider Grid.Row="1" Margin="10" Name="slider" ValueChanged="slider_ValueChanged"/><WrapPanel Grid.Row="1" Margin="0,40,0,0"><TextBlock Name="tb1" Width="120"/><TextBlock Name="tb2" Width="120"/></WrapPanel> 后台代码:private voidplayer_Loaded(object sender, RoutedEventArgs e){ DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(1000); timer.Tick += (ss, ee) => { //显示当前视频进度var ts = player.Position;tb1.Text = string.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds);slider.Value =ts.TotalMilliseconds; };timer.Start(); } private voidplayer_MediaOpened(object sender, RoutedEventArgs e){ //显示视频的时长var ts = player.NaturalDuration.TimeSpan; tb2.Text = string.Format("{0:00}:{1:00}:{2:00}", ts.Hours, ts.Minutes, ts.Seconds); slider.Maximum =ts.TotalMilliseconds; } private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e){ //调整视频进度var ts = TimeSpan.FromMilliseconds(e.NewValue);player.Position = ts; }。
JavaFX在一分钟内编写一个视频播放器

JavaFX在一分钟内编写一个视频播放器首先在Netbeans下新建一个JavaFX空项目。
然后从左边拖一个stage进来Stage是一个javaFX的基础,一个Stage下包含一个sence,就是我们放可视的组件的地方。
改一下大小,取个名字如下:1Stage{2title:"mediaplayer"3scene:Scene{4width:4005height:3506content:[78]9}10}接下来我们到底下的Swing组件里头拖进来一个按钮,并取个名字。
放到content中1SwingButton{2text:"Play"3action:function(){45}6}接下来添加播放器的代码。
因为播放器没有在左边列出来,我们需要import,然后手动写代码。
如下1importjavafx.scene.media.Media;2importjavafx.scene.media.MediaPlayer;3importjavafx.scene.media.MediaView;45//media是用来放电影地址的6varmedia=Media{source:"XX"}78//添加播放器9varplayer=MediaPlayer{media:media,autoPlay:false}接下来我们把各个部分组合起来:注意content里头新加的内容。
1importjavafx.stage.Stage;2importjavafx.scene.Scene;3importjavafx.ext.swing.SwingButton;4importjavafx.scene.media.Media;5importjavafx.scene.media.MediaPlayer;6importjavafx.scene.media.MediaView;78varmedia=Media{source:"XX"}9varplayer=MediaPlayer{media:media,autoPlay:false}1011Stage{12title:"mediaplayer"13scene:Scene{14width:40015height:35016content:[17MediaView{18mediaPlayer:player19}20SwingButton{21text:"player"22action:function(){23player.play()24}25}2627]28}29}如果按下运行,窗口还是半天没出来,请自行更换flv的源。
易语言编写视频播放器

易语⾔编写视频播放器
使⽤易语⾔制作视频播放器。
1、启动易语⾔。
2、选择⼯具栏中的“F 程序”,然后在弹出列表中选择“N 新建”。
3、第⼆步搞定后,在弹出的标题为“新建:”的窗⼝中⿏标左键单击“Windows窗⼝程序”,然后⿏标左键单击标题为“确定(o)”的按钮。
4、第三步完成后,在“窗⼝组件箱”中选择“外部组件”中的“播放器组件”。
5、⿏标左键单击“播放器”后,再在"窗⼝设计"那⾥单击⼀下,完成组件的安放。
6、①:在“__启动窗⼝_创建完毕”⼦程序下写代码:播放器1.地址=“”②:利⽤“拖放对象”控件③:利⽤“通⽤对话框”
7、我使⽤的是①,
.版本 2
.⽀持库 wmp9
.程序集窗⼝程序集1
.⼦程序 __启动窗⼝_创建完毕
播放器1.地址=取运⾏⽬录 () + “\0.avi”
8、运⾏易语⾔,看看效果吧!
总结:以上就是⽤易语⾔编写播放器的全部内容,感谢⼤家的阅读和对的⽀持。
WPF下面视频播放器

public ICommand SetFullScreenCommand { get; set; }//全屏命令public void SetFullScreen(object param)//全屏方法{if (MediaElement != null){_Rewinding = false;_Forwarding = false;_InrementalValue = 3;//初始化状态var content = Application.Current.Host.Content;//设置屏幕为全屏模式content.IsFullScreen = true;//将VideoBrush的内容设置为MediaElement视频内容VideoBrush objVideoBrush = new VideoBrush();objVideoBrush.SetSource(MyMediaElement);objVideoBrush.Stretch = Stretch.UniformToFill; //调整笔刷大小//在全屏模式下时需要一个Grid作为一个参数传入,//设置其背景内容为VideoBrush面板。
Grid objGrid = (Grid)param; //获取Grid面板参数objGrid.Visibility = Visibility.Visible; //显示GridobjGrid.Background = objVideoBrush; //设置其背景为VideoBrush}}private bool CanSetFullScreen(object param){var content = Application.Current.Host.Content; //仅在非全屏状态时才允许全屏return (!content.IsFullScreen);}界面布局部分就参考了一位网友的,感觉还不错就没改动。
C#在WPF中使用DirectX Dll做MP3播放器

在WPF中使用DirectX Dll做MP3播放器简价:这是一个简单的音乐播放器,可以一次播放一个MP3歌曲。
只包含一个快进,倒带,停止和播放等非常简单的功能。
技术信息:该项目引用以下几个外部的DLL.1)Microsoft.DirectX.AudioVideoPlayback.dll2)Microsoft.DirectX.Direct3D.dll3)Microsoft.DirectX.DirectPlay.dll4)Microsoft.DirectX.DirectSound.dll5)Microsoft.DirectX.dll以下代码是使用C#一步一步教你做一个简单的MP3播放器步骤:1)引用以上介绍的DLL2)引用以下Namespacesusing Microsoft.DirectX.AudioVideoPlayback;using Microsoft.DirectX;using Microsoft.DirectX.Direct3D;using Microsoft.DirectX.DirectPlay;using Microsoft.DirectX.DirectSound;3)全部代码如下namespace SimpleMP3Player{public partial class Form1 : Form{///<summary>/// 1.建立Audio Class///</summary>Audio song;public Form1(){InitializeComponent();}///<summary>/// 2.处理播放事件///</summary>///<param name="sender"></param>///<param name="e"></param>private void playBtn_Click(object sender, EventArgs e){openfile.Filter = "Audio Files(*.wav,*.mp3,*.cda)|*.wav;*.mp3;*.cda";if (openfile.ShowDialog() == DialogResult.OK){this.textBox1.Text = openfile.FileName;song = new Audio(this.textBox1.Text);//songTrack.Maximum = song.Duration;song.Play();//tm.Interval = 60;//tm.Start();//StLabel.Content = "Status : Playing";}}///<summary>/// 3.处理停止事件///</summary>///<param name="sender"></param>///<param name="e"></param>private void stopBtn_Click(object sender, EventArgs e) {try{song.Stop();}catch{}}///<summary>/// 4.处理进进事件///</summary>///<param name="sender"></param>///<param name="e"></param>private void forwBtn_Click(object sender, EventArgs e) {try{song.CurrentPosition += 2;}catch{try{song.CurrentPosition = song.Duration;}catch{}}}///<summary>/// 5.处理倒带事件///</summary>///<param name="sender"></param>///<param name="e"></param>private void rewindBtn_Click(object sender, EventArgs e) {try{song.CurrentPosition -= 2;}catch{try{song.CurrentPosition =0;}catch{}}}}}运行环境:a) Visual Studio 2008 Service Pack 1b) .Net Framework 3.5 + Service Pack 1c) DirectX Compatible Sound Cardd) Speakerse) Few Mp3 Songs to Test。
WPF媒体播放器(MediaElement)实例,实现进度和音量控制

Xaml代码
<Grid> <Grid.RowDefinitions> <RowDefinition Height="180*"/> <RowDefinition Height="89*"/> </Grid.RowDefinitions> <MediaElement x:Name="mediaElement" LoadedBehavior="Manual" Volume="{Binding ElementName=sliderVolume,Path=Value}" Source="F:\MyDocument\视频\COOLUI理念篇.mp4" MediaOpened="mediaElement_MediaOpened" HorizontalAlignment="Left" Height="175" Margin="7,20,0,0" VerticalAlignment="Top" Width="275" Grid.RowSpan="2"/>
HorizontalAlignment="Left" Margin="119,52,0,0" Grid.Row="1" VerticalAlignment="Top" Width="164" Height="18"/> <Label x:Name="label1" Content="进度:" HorizontalAlignment="Left" Margin="73,21,0,0" Grid.Row="1" VerticalAlignment="Top" Height="25" Width="46"/> <Slider x:Name="sliderPosition"
视频播放器的制作
C#中Windows Media Player控件使用实例|方法2009-09-23 09:05:20 来源:原创【大中小】浏览:2241次摘要:Windows Media Player是一种媒体播放器,可以播放当前最流行的音频、视频文件和大多数混合型的多媒体文件。
为了便于程序的开发,Visual Studio 2005集成开发环境提供了Windows Media Player控件,Windows Media Player控件Windows Media Player是一种媒体播放器,可以播放当前最流行的音频、视频文件和大多数混合型的多媒体文件。
为了便于程序的开发,Visual Studio 2005集成开发环境提供了Windows Media Player 控件,并且提供了相关的属性、方法,开发者根据提供的属性、方法完全可以实现Windows Media Player 播放器的所有功能。
在使用Windows Media Player控件进行程序开发前,必须将Windows Media Player控件添加到工具箱中,步骤如下所示。
(1)选择工具箱,并单击鼠标右键,在弹出的快捷菜单中选择“选择项”。
(2)弹出“选择工具箱项”对话框,选择“COM组件”选项卡。
(3)在COM组件列表中,选择名称为“Windows Media Player”,单击【确定】按钮,Windows Media Player控件添加成功,如图1所示。
图1 添加Windows Media Player控件表1和表2介绍Windows Media Player控件提供的主要属性和方法。
表1 Windows Media Player控件主要属性及说明另外,将Windows Media Player控件添加到窗体上,在该控件上单击鼠标右键,弹出“Windows Media Player控件属性”对话框,为Windows Media Player控件提供中文属性对话框,如图2所示。
WPF开发较为完整的音乐播放器(一)
WPF开发较为完整的⾳乐播放器(⼀)近来闲来有事,便想到⽤⾃⼰这段时间学习的知识写⼀个⾳乐播放器。
提前声明,我不擅长界⾯,因此做出来的界⾯的却有些次,但不是本系列⽂章的重点。
先讲下我们开发此⾳乐播放器所⽤到的技术:数据绑定、Xml、MediaPlayer类、数据模板等,将在之后陆续讲解。
来阐述下播放器开发的整体思路:构建⾳乐播放类⽤于播放⾳乐,⽤两个控件分别作为播放列表和播放控制,并且利⽤控件模板改变它们的界⾯,利⽤Xml数据读取类XmlListsReader来读取位于存放列表的xml,将歌曲名称、⽂件路径、持续时间歌⼿等信息读取到Product类中,并设置ListBox的ItemSouse为此类,采⽤数据模板显⽰数据。
好了,开始我们第⼀部分的教程--⾳乐播放类的构建。
话说利⽤WPF播放⾳乐有多种⽅法:MediaPlayer类,SoundPlayer类,以及使⽤DirectX Sound等。
若要选择⼀种功能较多,⽅便易⽤的⽅法,定要属MediaPlayer类了,唯⼀的限制就是需要依赖Windows Media Player(WMP)。
不过在Windows环境下,这⼀限制可以忽略不计,都是系统⾃带的,不是吗?当然,我们可以直接在窗⼝中防置MediaPlayer的操作代码,但是为了更正规化和可维护性,我们将它封装进MusicPlayer类中。
在类的开头,先来定义⼏个私有变量和公有的枚举(表⽰播放器的状态):public enum PlayState : int{stoped = 0,playing = 1,paused = 2}private MediaPlayer player = null;private Uri musicfile;private PlayState state;public Uri MusicFile{set{musicfile = value;}get{return musicfile;}}接下来写构造函数,⼀个带参数(⾳乐⽂件路径),⼀个不带参数的:public MusicPlay(){player = new MediaPlayer();}public MusicPlay(Uri file){Load(file);}构造函数将传⼊的⽂件路径传到Load⽅法中处理,以下是Load⽅法的代码:public void Load(Uri file){player = new MediaPlayer();MusicFile = file;player.Open(musicfile);}Load⽅法中设置了MusicFile(公有变量,指⽰⽂件路径),⽤MediaPlayer的Open⽅法加载了⾳乐⽂件。
WPF视频播放器自做
Cs代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;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;using Microsoft.Kinect.Toolkit.Controls; using Microsoft.Kinect;using Microsoft.Kinect.Interop;using Microsoft.Kinect.Toolkit;using System.Windows.Forms;using System.IO;using System.IO.Log;namespace mykinect{///<summary>///MainWindow.xaml的交互逻辑///</summary>publicpartialclass MainWindow : Window{private KinectSensorChooser sensorChooser; private System.Windows.Forms.Timer timer = new Timer() { };string root = "", pathMedia = "";public MainWindow(){InitializeComponent();timer.Tick += new EventHandler(timer_Tick); timer.Enabled = true;SetPlayer(false);Loaded += OnLoaded;InitPath();AddItemToListView();}void timer_Tick(object sender, EventArgs e){//模拟的做一些耗时的操作this.progress.Value =this.mediaElement.Position.Ticks;}privatevoid InitPath(){ApplicationPath ap = new ApplicationPath();root = ap.GetRtfPath("root");pathMedia = root + ap.GetRtfPath("pathMedia"); }//将视频目录下的视频名称添加到ListView中privatevoid AddItemToListView(){string[] files = Directory.GetFiles(pathMedia); foreach (string file in files){this.listView1.Items.Add(file.Substring(file.L astIndexOf('\\') + 1));}}//窗体加载时调用视频,进行播放privatevoid Window_Loaded(object sender, RoutedEventArgs e){MediaElementControl();}List<string>fileNames = new List<string>(); privatevoid MediaElementControl(){this.mediaElement.LoadedBehavior = MediaState.Manual;string[] files = Directory.GetFiles(pathMedia);foreach (string file in files){fileNames.Add(file.Substring(stIndexOf('\\') + 1));}this.mediaElement.Source = new Uri(files[0]);this.mediaElement.Play();}privatevoid mediaElement1_MediaEnded(object sender, RoutedEventArgs e){//获取当前播放视频的名称(格式为:xxx.wmv)string path =this.mediaElement.Source.LocalPath;string currentfileName =path.Substring(stIndexOf('\\') + 1);//对比名称列表,如果相同,则播放下一个,如果播放的是最后一个,则从第一个重新开始播放for (int i = 0; i<fileNames.Count; i++){if (currentfileName == fileNames[i]){if (i == fileNames.Count - 1){this.mediaElement.Source = new Uri(pathMedia + "//" + fileNames[0]);this.mediaElement.Play();}else{this.mediaElement.Source = new Uri(pathMedia + "//" + fileNames[i + 1]);this.mediaElement.Play();}break;}}}//播放列表选择时播放对应视频privatevoid listView1_SelectionChanged(object sender, SelectionChangedEventArgs e){//mediaElement.Stop();//SetPlayer(false);//我想在这里实现暂停的功能string fileName =this.listView1.SelectedValue.ToString(); this.mediaElement.Source = new Uri(pathMedia + "//" + fileName);//this.mediaElement.Play();//mediaElement.Source = newUri(openFileDialog.FileName, 0);progress.Value = 0;playBtn.IsEnabled = true;}privatevoid SetPlayer(bool bVal){stopBtn.IsEnabled = bVal;playBtn.IsEnabled = bVal;}privatevoid PlayerPause(){SetPlayer(true);if (playBtn.Content.ToString() == "Play"){mediaElement.Play();playBtn.Content = "Pause";mediaElement.ToolTip = "Click to Pause";}else{mediaElement.Pause();playBtn.Content = "Play";mediaElement.ToolTip = "Click to Play";}}privatevoid OnLoaded(object sender, RoutedEventArgs e){this.sensorChooser = new KinectSensorChooser();this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;this.sensorChooser.Start();}privatevoid SensorChooserOnKinectChanged(object sender, KinectChangedEventArgs args){bool error = false;if (args.OldSensor != null){try{args.OldSensor.DepthStream.Range = DepthRange.Default;args.OldSensor.SkeletonStream.EnableTrackingIn NearRange = false;args.OldSensor.DepthStream.Disable();args.OldSensor.SkeletonStream.Disable();}catch (InvalidOperationException){// KinectSensor might enter an invalid state while enabling/disabling streams or stream features.// E.g.: sensor might be abruptly unplugged. error = true;}}if (args.NewSensor != null){try{args.NewSensor.DepthStream.Enable(DepthImageFo rmat.Resolution640x480Fps30);args.NewSensor.SkeletonStream.Enable();try{args.NewSensor.DepthStream.Range =DepthRange.Near;args.NewSensor.SkeletonStream.EnableTrackingIn NearRange = true;args.NewSensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;}catch (InvalidOperationException){args.NewSensor.DepthStream.Range = DepthRange.Default;args.NewSensor.SkeletonStream.EnableTrackingIn NearRange = false;}}catch (InvalidOperationException){error = true;}}}privatevoid Button_Click(object sender,RoutedEventArgs e){OpenFileDialog openFileDialog =new OpenFileDialog();openFileDialog.Filter ="wmvfiles(*.wmv)|*.wmv|wmvfiles(*.avi)|*.avi";if (openFileDialog.ShowDialog() ==System.Windows.Forms.DialogResult.OK){System.Windows.MessageBox.Show(openFileDialog. FileName);mediaElement.Source =new Uri(openFileDialog.FileName, 0);playBtn.IsEnabled = true;}//MediaElementControl();}privatevoid playBtn_Click(object sender, RoutedEventArgs e){PlayerPause();}privatevoid Grid_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e){if (e.Key == Key.Escape)//Esc键{this.WindowState =System.Windows.WindowState.Normal;this.WindowStyle =System.Windows.WindowStyle.SingleBorderWindow; }}privatevoid Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e){}privatevoid volumeSlider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double>e)//目前就是这里存在bug{this.progress.Maximum =this.mediaElement.NaturalDuration.TimeSpan.Tic ks;this.mediaElement.Position =new TimeSpan((long)this.progress.Value);}privatevoid mediaElement_MouseLeftButtonUp(obje ct sender, MouseButtonEventArgs e){PlayerPause();}privatevoid stopBtn_Click(object sender, RoutedEventArgs e){mediaElement.Stop();playBtn.Content = "Play";SetPlayer(false);playBtn.IsEnabled = true;}}}XAML代码:<Window x:Class="mykinect.MainWindow"xmlns="/winfx/2006 /xaml/presentation"xmlns:x="/winfx/20 06/xaml"xmlns:k="/kinect/2 013"Title="MainWindow" Height="700" Width="1050"> <Grid><k:KinectSensorChooserUI HorizontalAlignment="C enter"VerticalAlignment="Top"Name="sensorChooserUi" /><RectangleFill="#FFF4F4F5"HorizontalAlignment="Left" Height="542" Margin="10,45,0,0"Stroke="Yellow"VerticalAlignment="Top"Width="793"/><MediaElement HorizontalAlignment="Left"Height="542" Name="mediaElement"Margin="10,45,0,0"VerticalAlignment="Top" Width="793"Volume="{Binding ElementName=volumeSlider, Path=Value}"LoadedBehavior="Manual" /><Slider x:Name="progress" Height="22"Margin="10,587,239,0"VerticalAlignment="Top"Va lueChanged="volumeSlider1_ValueChanged"/><Slider x:Name="volumeSlider" Minimum="0" Maximum="1"HorizontalAlignment="Left"Margin="649,619,0,0"VerticalAlignment="Top" Width="154"ValueChanged="Slider_ValueChanged"/ ><Button Content="Open File"HorizontalAlignment="Left" Height="23" Margin="10,614,0,0"VerticalAlignment="Top" Width="127" Click="Button_Click"/><Button x:Name="playBtn"Content="Play"HorizontalAlignment="Left" Height="23"Margin="219,614,0,0"VerticalAlignment="Top"Width="101" Click="playBtn_Click"/><ListView HorizontalAlignment="Left"Height="303" Margin="808,45,0,0"Name="listView1"SelectionMode="Single"IsSynchr onizedWithCurrentItem="{x:Null}"SelectionChang ed="listView1_SelectionChanged" VerticalAlignment="Top" Width="224"><ListView.View><GridView><GridViewColumn/></GridView></ListView.View></ListView><Button x:Name="stopBtn"Content="Stop"HorizontalAlignment="Left" Margin="417,614,0,0"VerticalAlignment="Top" Width="75"RenderTransformOrigin="0.507,1.211" Height="23" Click="stopBtn_Click"/></Grid></Window>ApplicationPath代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;namespace mykinect{class ApplicationPath{privatereadonlystaticstring ImagePath = Environment.CurrentDirectory + "\\image\\"; privatereadonlystaticstring RtfPath = Environment.CurrentDirectory + "\\rtf\\";XmlDocument xDoc = new XmlDocument();public ApplicationPath(){xDoc.Load(getAppConfigPath());}publicstaticstring getImagePath(){return ImagePath;}publicstaticstring getRtfPath(){return RtfPath;}publicstring getAppConfigPath(){return Environment.CurrentDirectory +"\\App.config";}//获取App.config值publicstring GetRtfPath(string appKey){try{XmlNode xNode;XmlElement xElem;xNode = xDoc.SelectSingleNode("//appSettings");xElem =(XmlElement)xNode.SelectSingleNode("//add[@key ='" + appKey + "']");if (xElem != null){return xElem.GetAttribute("value");}elsereturn"";}catch (Exception){return"";}}}}App.config:<?xml version="1.0" encoding="utf-8"?><configuration><appSettings><add key="root" value="D:\" /><add key="pathMedia" value="英雄时刻\" />//根据需要自己改改就行</appSettings></configuration>。
用wpf做的音乐播放器
Wpf之音乐播放器程序界面:前台代码:<Window x:Class="音°?乐¤?播£¤放¤?器¡Â.MainWi ndow"xmlns="/winfx/2006/xaml/presentation"xmlns:x="/winfx/2006/xaml"Title="音°?乐¤?播£¤放¤?器¡Â" Height="361" Width="489" Loaded="Wi ndow_Loaded" Name="音°?乐¤?播£¤放¤?器¡Â"><Grid Background="Black"><Grid.ColumnDefinitions><ColumnDefinition Width="340*"></C olumnDefinition><ColumnDefinition Width="127*"></C olumnDefinition></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="*"></R owDefinition><RowDefinition Height="102"></RowDefinition></Grid.RowDefinitions><Grid Grid.Column="0" Grid.Row="0" Background="Black"><Grid.RowDefinitions><RowDefinition Height="*"></RowDefinition><RowDefinition Height="38"></RowDefinition></Grid.RowDefinitions><Grid Grid.Row="1" Background="Black"><Grid.ColumnDefinitions><ColumnDefinition Width="60.5"></ColumnDefinition><ColumnDefinition Width="60.5"></ColumnDefinition><ColumnDefinition Width="*" /></Grid.ColumnDefinitions><StackPanel Orientati on="Vertical" Grid.Column="2"><Label Content="当Ì¡À前¡ã播£¤放¤?:êo" Height="20" FontSize="10" Name="lable1" VerticalAlignment="Top" Foreground="Red"></Label><Slider Name="slider1"Value="{BindingElementName=me,Path=me.position,Mode=TwoWay}" VerticalAlignment="Center"ValueChanged="slider1_ValueChanged"></Slider></StackPanel><Label Name="txtruntime"Grid.Column="0" Horizontal Alignment="Stretch" VerticalAlignment="Center" FontSize="12.5" Foreground="Red"></Label><Label Name="txttataltime" Grid.Column="1" VerticalAlignment="Center"FontSize="12.5" Foreground="Red"></Label></Grid><MediaElement Name="me" Grid.Column="0" Grid.Row="0"LoadedBehavior="Manual" MediaEnded="me_MediaEnded" /></Grid><ListBox Name="listBox1" Grid.Column="1" Grid.RowSpan="2"SelectionChanged="li stBox1_SelectionChanged" MouseDoubleClick="listBox1_MouseDoubleClick_1" Foreground="AntiqueWhite" Background="Black"BorderBrush="Blue" BorderThickness="5"><ListBox.ContextMenu><ContextMenu><MenuItem Header="添¬¨ª加¨®单Ì£¤个?媒?体¬?文?件t" Click="MenuItem_Click" ></MenuItem><MenuItem Header="删¦?除y单Ì£¤个?媒?体¬?文?件t" Click="MenuItem_Click_1"></MenuItem><MenuItem Header="清?空?列¢D表À¨ª" Click="MenuItem_Click_2"></MenuItem></ContextMenu></ListBox.ContextMenu></ListBox><Grid Grid.Row="1" Grid.Column="0"><Grid.ColumnDefinitions><ColumnDefinition></ColumnDefinition><ColumnDefinition></ColumnDefinition><ColumnDefinition></ColumnDefinition></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition></RowDefinition><RowDefinition></RowDefinition><RowDefinition></RowDefinition></Grid.RowDefinitions><Button Background="Black" Grid.Row="1" Content="快¨¬退ª?" Name="btnback"Click="btnback_Click_1" Foreground="Blue" BorderBrush="Blue" BorderThickness="5" /><Button Background="Black" Content="快¨¬进?" Grid.Column="2" Grid.Row="1"Name="btngo" Click="btngo_Click_1"Foreground="Blue" BorderBrush="Blue" BorderThickness="5"/> <Button Background="Black" Content="播£¤放¤?" Grid.Row="2" Grid.Column="1"Name="btnplayhold" Click="btnplayhold_Click" Foreground="Blue" BorderBrush="Blue" BorderThickness="5" ></Button><Button Background="Black" Content="打䨰开a" Grid.Row="2" Name="btnopen"Grid.Column="0" Click="btnopen_Click" Foreground="Blue" B orderBrush="Blue"BorderThickness="5"></Button><Button Background="Black" Content="退ª?出?" Grid.Column="2" Name="btnclose"Grid.Row="2" Click="btnclose_Click" Foreground="Blue" BorderBrush="Blue"BorderThickness="5" ></Button><Button Background="Black" Content="上¦?一°?曲¨²" Name="btnfor" Click="btnfor_Click" Grid.Row="0" Grid.Column="0 " Foreground="Blue" BorderBrush="Blue" BorderThickness="5"></Button><Button Background="Black" Content="下?一°?曲¨²" Grid.Column="2" Name="btnnext" Click="btnnext_Click" Foreground="Blue" BorderBrush="Blue" BorderThickness="5" ></Button> <Slider Grid.Column="1"Name="slidvolume"Grid.Row="1"Maximum="1" Minimum="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Stretch" ValueChanged="slidvol ume_ValueChanged" SmallChange="0.1" VerticalAlignment="Center" LargeChange="0.1" /><Button Background="Black" Content="列¢D表À¨ª循-环¡¤" Grid.Column="1" Grid.Row="0" Name="btnplaymode" Click="btnplaymode_Click" Foreground="Blue" BorderBrush="Blue" BorderThickness="5"/></Grid></Grid></Wi ndow>后台源代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;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;using System.Windows.Forms;using System.IO;using System.Runtime;using System.Windows.Media.Animation;using System.Threading;namespace音°?乐¤?播£¤放¤?器¡Â{///<summary>/// MainWindow.xaml 的Ì?交?互£¤逻?辑-///</summary>public partial class MainWindow : Window{List<string> s = new List<string>();byte[] bs;List<string> str8 = null;private bool ?flag = null;private bool? flag1;FolderBrowserDialog fbd = new FolderBrowserDialog();StringBuilder sb = new StringBuilder();private string[] strm = null;public MainWindow(){InitializeComponent();}private void Window_Loaded(object sender, RoutedEventArgs e){flag = null;flag1=null;str8 = new List<string>();slidvolume.Value =0.3;me.Volume = 0.3;txttataltime.Content = me.Position.ToString();txtruntime.Content = me.Positi on.ToString();listBox1.Items.Clear();FileStream fs1 = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\歌¨¨曲¨²列¢D 表À¨ª.txt", FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);byte[] bt = new byte[fs1.Length];fs1.Read(bt, 0, bt.Length);string str = Encodi ng.Default.GetString(bt);string[] str4 = str.Split(new string[] { "\r\n" }, StringSplitOptions.None);s = str4.Distinct().ToList();for (int i = 0; i <= s.Count - 1; i++){if (s[i].LastIndexOf("\\")>=0){listBox1.Items.Add(s[i].Substring(s[i].LastIndexOf("\\") + 1));str8.Add(s[i].Substring(0, s[i].LastIndexOf("\\")));}}System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();t.Enabled = true;t.Tick += new EventHandler(t_Tick);t.Interval = 1100;t.Start();}private void btnfor_Click(object sender, RoutedEventArgs e){try{if (flag1 ==null){listBox1.SelectedIndex--;}if(flag1==true){Random rnd = new Random();listBox1.SelectedIndex = rnd.Next(0, listBox1.Items.Count - 1);}if(flag1==false){}if (listBox1.SelectedIndex < 0){(listBox1.SelectedIndex) = (listBox1.Items.Count - 1);}musicplay();}catch { System.Wi ndows.Forms.MessageBox.Show("请?选?择?歌¨¨曲¨²"); } }private void btnnext_Click(object sender, RoutedEventArgs e){if (flag1 == null){if (listBox1.SelectedIndex <listBox1.Items.Count - 1){listBox1.SelectedIndex++;musicplay();return;}if (listBox1.SelectedIndex >= listBox1.Items.Count - 1){(listBox1.SelectedIndex) = 0;}}if (flag1 == true){Random rnd = new Random();listBox1.SelectedIndex = rnd.Next(0, listBox1.Items.Count - 1);}if (flag1 == false){}musicplay();}private void btnplayhold_Click(object sender, RoutedEventArgs e){if (flag == true){btnplayhold.Content = "暂Y停ª¡ê";me.Pause();flag = false;return;}else{if( flag==false ){me.Play();btnplayhold.Content = "播£¤放¤?";flag = true;return;}else{btnplayhold.Content = "播£¤放¤?";musicplay();return;}}}private void btnopen_Click(object sender, RoutedEventArgs e){fbd.ShowDialog();byte[] bs;string[] str={"*.mp3","*.rmvb","*.jpg","*.avi","*.mp4","*.rm"};foreach (string s in str){if (fbd.SelectedPath == ""){System.Windows.Forms.MessageBox.Show("请?选?择?正y确¨¡¤的Ì?文?件t夹D");return;}strm = Directory.GetFiles(fbd.SelectedPath, s);str8.Add(fbd.SelectedPath);for (int i = 0; i <= strm.Length - 1; i++){sb.Append(strm[i]);sb.Append("\r\n");listBox1.Items.Add(strm[i].Substring(strm[i].LastIndexOf("\\") + 1));}}FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory+"\\歌¨¨曲¨²列¢D表À¨ª.txt", FileMode.Append, FileAccess.Write, FileShare.ReadWrite);bs = Encoding.Default.GetBytes(sb.ToString());fs.Write(bs, 0, bs.Length);fs.Flush();fs.Close();if (listBox1.Items.Count == 0){System.Windows.Forms.MessageB ox.Show("请?选?择?正y确¨¡¤的Ì?文?件t夹D");}}private void btncl ose_Click(object sender, RoutedEventArgs e){this.Close();}private void listBox1_MouseDoubleClick_1(object sender, MouseButtonEventArgs e){musicplay();}private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e){flag = null;}private void btngo_Click_1(object sender, RoutedEventArgs e){if(listBox1.SelectedIndex+1!=0){TimeSpan ts = new TimeSpan(0,0,3);me.Position = me.Position.Add(ts);}}private void btnback_Click_1(object sender, RoutedEventArgs e){if(listBox1.SelectedIndex+1!=0){TimeSpan ts = new TimeSpan(0, 0, 3);me.Position = me.Position-ts;}}private void slidvolume_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {me.ScrubbingEnabled = true;me.Volume = slidvolume.Value;}private void musicplay(){Thread.Sleep(1000);me.Close();if (listBox1.SelectedItem.ToString() ==null){System.Windows.Forms.MessageBox.Show("请?选?择?歌¨¨曲¨²");return;}for (int i = 0; i <= str8.Count-1;i++ ){if (str8[i] !=""){if (File.Exists(str8[i] + "\\" + listBox1.SelectedItem.ToString()) == true){lable1.Content = "当Ì¡À前¡ã播£¤放¤?:êo" + listB ox1.SelectedItem.ToString();lable1.Width = listBox1.SelectedItem.ToString().Length * 20;me.Source = new Uri(str8[i] + "\\" + listB ox1.SelectedItem.ToString().ToString(), UriKind.RelativeOrAbsolute);me.Play();btnplayhold.Content = "播£¤放¤?";flag = true;return;}else {TimeSpan ts = new TimeSpan(0,0,0);me.Position = ts;lable1.Content = "当Ì¡À前¡ã播£¤放¤?:êo 歌¨¨曲¨²不?存ä?在¨²,请?从䨮新?加¨®载?!ê?!ê?!ê?" ;lable1.Width = listB ox1.SelectedItem.ToString().Length *40;txttataltime.Content = "00:00:00";}}}}private void t_Tick(object sender, EventArgs e){string str = me.NaturalDuration.ToString();if (me.Position == me.NaturalDurati on){me.Close();string[] str3 = str.Split(':');double a = Convert.ToDouble(str3[0]);double b = Convert.ToDouble(str3[1]);double c = Convert.ToDouble(str3[2]);slider1.Maximum = (a * 3600 + b * 60 + c);}if (str !="Automatic"){string[] str3 = str.Split(':');double a = Convert.ToDouble(str3[0]);double b = Convert.ToDouble(str3[1]);double c = Convert.ToDouble(str3[2]);slider1.Maximum = (a * 3600 + b * 60 + c);txttataltime.Content = me.NaturalDuration.ToString();}if (str == "Automatic"){str = me.Position.ToString();}slider1.Minimum = 0;txtruntime.Content = me.Position.ToString();string s = me.Position.ToString();string[] str2 = s.Split(':');double d = Convert.ToDouble(str2[0]);double g = Convert.ToDouble(str2[1]);double f = Convert.ToDouble(str2[2]);slider1.Value = (d * 3600 + g * 60 + f);}private void btnplaymode_Click(object sender, RoutedEventArgs e){if (flag1 == null){btnplaymode.Content = "随?机¨²播£¤放¤?";flag1 = true;return;}if (flag1 == true){btnplaymode.Content = "单Ì£¤曲¨²循-环¡¤";flag1 = false;return;}if (flag1 == false){btnplaymode.Content = "列¢D表À¨ª循-环¡¤";flag1 = null;return;}}private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e){me.Scrubbi ngEnabled = true;me.Position = TimeSpan.FromSeconds(slider1.Value);}private void MenuItem_Click(object sender, RoutedEventArgs e){OpenFileDialog ofp = new OpenFileDialog();ofp.Multi select = true;ofp.ShowDialog();if (ofp.FileName == ""){System.Windows.Forms.MessageBox.Show("请?选?择?正y确¨¡¤的Ì?文?件t");return;}for (int i = 0; i <= ofp.FileNames.Count() - 1; i++){sb.Append(ofp.FileNames[i]);sb.Append("\r\n");if (ofp.SafeFileNames[i] != ""){listBox1.Items.Add(ofp.SafeFileNames[i]);str8.Add(ofp.FileNames[i].Substring(0, ofp.FileNames[i].LastIndexOf("\\") + 1));}}FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\歌¨¨曲¨²列¢D表À¨ª.txt", FileMode.Append, FileAccess.Write, FileShare.ReadWrite);bs = Encoding.Default.GetBytes(sb.ToString());fs.Write(bs, 0, bs.Length);fs.Flush();fs.Close();}private void MenuItem_Click_1(object sender, RoutedEventArgs e){try{FileStream fs1 = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\歌¨¨曲¨²列¢D表À¨ª.txt", FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite);byte[] bt = new byte[fs1.Length];fs1.Read(bt, 0, bt.Length);fs1.Dispose();string str = Encoding.Default.GetString(bt);string[] s = str.Split(new string[] { "\r\n" }, StringSplitOptions.None);List<string> list = new List<string>(s);if (listBox1.SelectedItem != null){for (int i = 0; i < s.Length - 1; i++){if (s[i].Contains(listBox1.SelectedItem.ToString())){list.RemoveAt(i);}}}s = (string[])list.ToArray();FileInfo file = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "\\歌¨¨曲¨²列¢D表À¨ª.txt");file.Refresh();file.Delete();List<string> li = new List<string>();li=s.Distinct().ToList();StringBuilder sb = new StringBuilder();for (int i = 0; i <= li.Count - 1; i++){sb.Append(li[i]);sb.Append("\r\n");}FileStream fs2 = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\歌¨¨曲¨²列¢D表À¨ª.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);bs = Encoding.Default.GetBytes(sb.ToString());fs2.Write(bs, 0, bs.Length);fs2.Flush();fs2.Close();}catch {}listBox1.Items.Remove(listBox1.SelectedItem);}private void MenuItem_Click_2(object sender, RoutedEventArgs e){me.Stop();listBox1.Items.Clear();FileInfo file = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "\\歌¨¨曲¨²列¢D表À¨ª.txt");file.Refresh();file.Delete();}private void me_MediaEnded(object sender, RoutedEventArgs e){if (flag1 == null){if (listBox1.SelectedIndex == listBox1.Items.Count - 1){listBox1.SelectedIndex = 0;}else{listBox1.SelectedIndex++;}musicplay();}if (flag1 == true){Random rnd = new Random();listBox1.SelectedIndex = rnd.Next(0, listBox1.Items.Count - 1);musicplay();}if (flag1 == false){musicplay();}}}}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
namespace mykinect { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { private KinectSensorChooser sensorChooser; private System.Windows.Forms.Timer timer = new Timer() { }; string root = "", pathMedia = ""; public MainWindow() { InitializeComponent(); timer.Tick += new EventHandler(timer_Tick); timer.Enabled = true; SetPlayer(false); Loaded += OnLoaded;
try { args.OldSensor.DepthStream.Range = DepthRange.Default; args.OldSensor.SkeletonStream.EnableTrackingIn NearRange = false; args.OldSensor.DepthStream.Disable(); args.OldSensor.SkeletonStream.Disable(); } catch (InvalidOperationException) { // KinectSensor might enter an invalid state while enabling/disabling streams or stream features. // E.g.: sensor might be abruptly unplugged. error = true;
{ this.mediaElement.LoadedBehavior = MediaState.Manual; string[] files = Directory.GetFiles(pathMedia); foreach (string file in files) { fileNames.Add(file.Substring(stIndexOf( '\\') + 1)); } this.mediaElement.Source = new Uri(files[0]); this.mediaElement.Play(); } private void mediaElement1_MediaEnded(object sender, RoutedEventArgs e)
InitPath(); AddItemToListView(); } void timer_Tick(object sender, EventArgs e) { //模拟的做一些耗时的操作 this.progress.Value = this.mediaElement.Position.Ticks; } private void InitPath() { ApplicationPath ap = new ApplicationPath(); root = ap.GetRtfPath("root"); pathMedia = root + ap.GetRtfPath("pathMedia"); }
//mediaElement.Stop(); //SetPlayer(false);//我想在这里实 现暂停的功能 string fileName = this.listView1.SelectedValue.ToString(); this.mediaElement.Source = new Uri(pathMedia + "//" + fileName); //this.mediaElement.Play(); //mediaElement.Source = new Uri(openFileDialog.FileName, 0); progress.Value = 0; playBtn.IsEnabled = true; }
//将视频目录下的视频名称添加到ListView 中 private void AddItemToListView() { string[] files = Directory.GetFiles(pathMedia); foreach (string file in files) { this.listView1.Items.Add(file.Substring(file.L astIndexOf('\\') + 1)); } } //窗体加载时调用视频,进行播放 private void Window_Loaded(object sender, RoutedEventArgs e) { MediaElementControl(); } List<string> fileNames = new List<string>(); private void MediaElementControl()
{ //获取当前播放视频的名称(格式为: xxx.wmv) string path = this.mediaElement.Source.LocalPath; string currentfileName = path.Substring(stIndexOf('\\') + 1); //对比名称列表,如果相同,则播放下 一个,如果播放的是最后一个,则从第一个重新开始 播放 for (int i = 0; i < fileNames.Count; i++) { if (currentfileName == fileNames[i]) { if (i == fileNames.Count 1) { this.mediaElement.Source = new Uri(pathMedia +
private void SetPlayer(bool bVal) { stopBtn.IsEnabled = bVal; playBtn.IsEnabled = bVal;
} private void PlayerPause() { SetPlayer(true); if (playBtn.Content.ToString() == "Play") { mediaElement.Play(); playBtn.Content = "Pause"; mediaElement.ToolTip = "Click to Pause"; } else { mediaElement.Pause(); playBtn.Content = "Play"; mediaElement.ToolTip = "Click to Play"; }
"//" + fileNames[0]); this.mediaElement.Play(); } else { this.mediaElement.Source = new Uri(pathMedia + "//" + fileNames[i + 1]); this.mediaElement.Play(); } break; } } } //播放列表选择时播放对应视频 private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e) {
} } if (args.NewSensor != null) { try { args.NewSensor.DepthStream.Enable(DepthImageFo rmat.Resolution640x480Fps30); args.NewSensor.SkeletonStream.Enable(); try { args.NewSensor.DepthStream.Range = DepthRange.Near; args.NewSensor.SkeletonStream.EnableTrackingIn NearRange = true;
பைடு நூலகம்
args.NewSensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated; } catch (InvalidOperationException) { args.NewSensor.DepthStream.Range = DepthRange.Default; args.NewSensor.SkeletonStream.EnableTrackingIn NearRange = false; } } catch (InvalidOperationException) { error = true; } } }
private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "wmv files(*.wmv)|*.wmv|wmv files(*.avi)|*.avi"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.Windows.MessageBox.Show(openFileDialog. FileName); mediaElement.Source = new Uri(openFileDialog.FileName, 0); playBtn.IsEnabled = true; } //MediaElementControl(); } private void playBtn_Click(object