在此问个问题,MediaElement播放本地和http上的视频没问题,但是ftp的怎么在本例中播放不了

若高手了解,请不吝赐教

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 Microsoft.Win32;
using System.IO;
using System.Windows.Threading;
using System.Threading;
using System.Data;
using System.Windows.Forms; namespace MediaPlayer_Beta
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{ DispatcherTimer timer; public delegate void timerTick();
timerTick tick; bool isDragging = false;
bool fileIsPlaying = false;
string sec, min, hours; public MainWindow()
{
this.Left = ;
this.Top = ;
InitializeComponent();
seekSlider.Width = SystemParameters.MaximizedPrimaryScreenWidth - ;
this.WindowState = System.Windows.WindowState.Maximized;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds();
timer.Tick += new EventHandler(timer_Tick);
tick = new timerTick(changeStatus);
} void timer_Tick(object sender, EventArgs e)
{
Dispatcher.Invoke(tick);
} //visualize progressBar
void changeStatus()
{
if (fileIsPlaying)
{ #region customizeTime
if (mediaElement.Position.Seconds < )
sec = "" + mediaElement.Position.Seconds.ToString();
else
sec = mediaElement.Position.Seconds.ToString(); if (mediaElement.Position.Minutes < )
min = "" + mediaElement.Position.Minutes.ToString();
else
min = mediaElement.Position.Minutes.ToString(); if (mediaElement.Position.Hours < )
hours = "" + mediaElement.Position.Hours.ToString();
else
hours = mediaElement.Position.Hours.ToString(); #endregion customizeTime seekSlider.Value = mediaElement.Position.TotalMilliseconds;
progressBar.Value = mediaElement.Position.TotalMilliseconds; if (mediaElement.Position.Hours == )
{ currentTimeTextBlock.Text = min + ":" + sec;
}
else
{
currentTimeTextBlock.Text = hours + ":" + min + ":" + sec;
}
}
} //open the file
private void openFileButton_Click(object sender, RoutedEventArgs e)
{
string FileName = "http://mschannel9.vo.msecnd.net/o9/mix/09/wmv/key01.wmv";
//"ftp://test:123456@192.168.1.75/media/Linux.wmv";//Ftp测试不能播放,需下载本地再打开
//"e:\\text\\dian\\media\\test.avi";
mediaElement.Source = new Uri(FileName);
Thread.Sleep();
mediaElement.Close();
mediaElement.Play();
} //occurs when the file is opened
public void mediaElement_MediaOpened(object sender, RoutedEventArgs e)
{
timer.Start();
fileIsPlaying = true;
openMedia();
} //opens media,adds file to playlist and gets file info
public void openMedia()
{
InitializePropertyValues();
try
{
#region customizeTime
if (mediaElement.NaturalDuration.TimeSpan.Seconds < )
sec = "" + mediaElement.Position.Seconds.ToString();
else
sec = mediaElement.NaturalDuration.TimeSpan.Seconds.ToString(); if (mediaElement.NaturalDuration.TimeSpan.Minutes < )
min = "" + mediaElement.NaturalDuration.TimeSpan.Minutes.ToString();
else
min = mediaElement.NaturalDuration.TimeSpan.Minutes.ToString(); if (mediaElement.NaturalDuration.TimeSpan.Hours < )
hours = "" + mediaElement.NaturalDuration.TimeSpan.Hours.ToString();
else
hours = mediaElement.NaturalDuration.TimeSpan.Hours.ToString(); if (mediaElement.NaturalDuration.TimeSpan.Hours == )
{ endTimeTextBlock.Text = min + ":" + sec;
}
else
{
endTimeTextBlock.Text = hours + ":" + min + ":" + sec;
} #endregion customizeTime
}
catch { }
string path = mediaElement.Source.LocalPath.ToString(); double duration = mediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
seekSlider.Maximum = duration;
progressBar.Maximum = duration; mediaElement.Volume = volumeSlider.Value;
mediaElement.SpeedRatio = speedRatioSlider.Value + ;
mediaElement.ScrubbingEnabled = true; volumeSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(volumeSlider_ValueChanged);
speedRatioSlider.ValueChanged += new RoutedPropertyChangedEventHandler<double>(speedRatioSlider_ValueChanged);
} //occurs when the file is done playing
private void mediaElement_MediaEnded(object sender, RoutedEventArgs e)
{
mediaElement.Stop();
volumeSlider.ValueChanged -= new RoutedPropertyChangedEventHandler<double>(volumeSlider_ValueChanged);
speedRatioSlider.ValueChanged -= new RoutedPropertyChangedEventHandler<double>(speedRatioSlider_ValueChanged);
} //initialize properties of file
void InitializePropertyValues()
{
mediaElement.Volume = (double)volumeSlider.Value;
mediaElement.SpeedRatio = (double)speedRatioSlider.Value + ;
} //seek to desirable position of the file
private void seekSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
TimeSpan ts = new TimeSpan(, , , , (int)seekSlider.Value); changePostion(ts);
} //mouse down on slide bar in order to seek
private void seekSlider_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
isDragging = true;
fileIsPlaying = false;
} private void seekSlider_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (isDragging)
{
TimeSpan ts = new TimeSpan(, , , , (int)seekSlider.Value);
changePostion(ts);
fileIsPlaying = true;
}
isDragging = false;
} //change position of the file
void changePostion(TimeSpan ts)
{
mediaElement.Position = ts;
} //change the speed of the playback
void speedRatioSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
mediaElement.SpeedRatio = speedRatioSlider.Value + ;
speedTextBlock.Text = speedRatioSlider.Value + "x";
} //play the file
private void playButton__Click(object sender, RoutedEventArgs e)
{
fileIsPlaying = true;
mediaElement.Play();
timer.Start();
} //pause the file
private void pauseButton_Click(object sender, RoutedEventArgs e)
{
fileIsPlaying = false;
mediaElement.Pause();
timer.Stop();
} //stop the file
private void stopButton_Click(object sender, RoutedEventArgs e)
{
fileIsPlaying = false;
timer.Stop();
mediaElement.Stop();
seekSlider.Value = ;
progressBar.Value = ;
currentTimeTextBlock.Text = "00:00";
} //turn volume up-down
private void volumeSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
mediaElement.Volume = volumeSlider.Value;
} }
}
<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"
mc:Ignorable="d"
x:Class="MediaPlayer_Beta.MainWindow"
IsHitTestVisible="True" Background="#00000000" ResizeMode="CanResize" IsTabStop="True"
Grid.IsSharedSizeScope="True" UseLayoutRounding="True" HorizontalContentAlignment="Center"
WindowStyle="ThreeDBorderWindow" AllowsTransparency="False" d:DesignHeight="" d:DesignWidth="">
<Grid x:Name="mainGrid" Background="#FF0A0A0A" Height="{Binding}">
<Grid.RowDefinitions>
<RowDefinition Height="286*" />
<RowDefinition Height="" />
<RowDefinition Height="" />
</Grid.RowDefinitions>
<MediaElement MediaEnded="mediaElement_MediaEnded" MediaOpened="mediaElement_MediaOpened" LoadedBehavior="Manual" HorizontalAlignment="Right" Name="mediaElement" VerticalAlignment="Bottom" Opacity="" AllowDrop="True" Stretch="Fill" IsMuted="False" />
<Button Content="打开" Height="" HorizontalAlignment="Left" Margin="220,0,0,0" Name="openFileButton" VerticalAlignment="Top" Width="" Click="openFileButton_Click" Background="#FF030303" Foreground="#FFE8E8E8" Grid.Row="" />
<Button x:Name="stopButton" Content="停止" Margin="149,0,0,0" Click="stopButton_Click" Background="#FF030303" Foreground="#FFE8E8E8" HorizontalAlignment="Left" Width="" Grid.Row="" />
<Slider Height="" HorizontalAlignment="Left" Margin="292,0,0,0" Name="volumeSlider" VerticalAlignment="Top" Width="" Value="0.5" Maximum="" SmallChange="0.01" LargeChange="0.1" Background="Black" Foreground="#FFDBDBDB" IsMoveToPointEnabled="True" Grid.Row=""></Slider>
<Slider Name="speedRatioSlider" VerticalAlignment="Center" Value="" Width="" Margin="385,0,0,0" Maximum="" SmallChange="" Background="Black" UseLayoutRounding="True" TickPlacement="BottomRight" Foreground="#FFDBDBDB" Height="" Grid.Row="" HorizontalAlignment="Left"></Slider>
<Button x:Name="pauseButton" Content="暂停" Margin="71,0,0,0" Click="pauseButton_Click" Background="#FF030303" Foreground="#FFE8E8E8" Width="" HorizontalAlignment="Left" Grid.Row="" />
<Button x:Name="playButton_" Content="播放" HorizontalAlignment="Left" Width="" Click="playButton__Click" ClipToBounds="True" Background="#FF030303" Foreground="#FFE8E8E8" Grid.Row="" Margin="4,0,0,0" />
<TextBlock Height="" Name="endTimeTextBlock" Text="00:00" Width="" Background="{x:Null}" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="495,0,0,0" FlowDirection="RightToLeft" Grid.Row="" TextAlignment="Center"></TextBlock>
<TextBlock Height="" Name="currentTimeTextBlock" Text="00:00" Width="" Background="Black" Foreground="#FFDBDBDB" TextAlignment="Center" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4,0,0,0" Grid.Row=""></TextBlock>
<Slider Width="{Binding}" PreviewMouseLeftButtonUp="seekSlider_PreviewMouseLeftButtonUp" PreviewMouseLeftButtonDown="seekSlider_PreviewMouseLeftButtonDown" MouseLeftButtonUp="seekSlider_MouseLeftButtonUp" Name="seekSlider" Background="{x:Null}" Foreground="Red" BorderBrush="{x:Null}" IsMoveToPointEnabled="True" TickPlacement="None" SnapsToDevicePixels="False" OpacityMask="{x:Null}" IsManipulationEnabled="True" IsSnapToTickEnabled="False" IsSelectionRangeEnabled="False" IsTabStop="False" AutoToolTipPlacement="None" AllowDrop="False" Height="" VerticalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Grid.Row="" Margin="68,0,68,0"></Slider>
<ProgressBar Height="" Name="progressBar" Background="#00000000" BorderBrush="Black" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="68,0,68,0" Grid.Row="" IsHitTestVisible="False" BorderThickness="" Foreground="#FF0089FF"></ProgressBar>
<TextBlock Height="" Name="speedTextBlock" Text="0x" Width="" Background="{x:Null}" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="460,7,0,0" FlowDirection="RightToLeft" Grid.Row="" TextAlignment="Right"></TextBlock>
</Grid>
</Window>

WPF MediaElement播放器2的更多相关文章

  1. WPF 媒体播放器(MediaElement)实例,实现进度和音量控制

    WPF 视频音频播放控件MediaElement实现进度控制,音量控制实例 说明: 1.Volume控制音量的大小,double类型,并且实现了属性依赖,可以用来双向绑定:在 0 和 1. 之间的线性 ...

  2. WPF 媒体播放器(MediaElement)使用实例(转)

    在WPF 中可以使用MediaElement 为应用程序添加媒体播放控件,以完成播放音频.视频功能.由于MediaElement 属于UIElement,所以它同时也支持鼠标及键盘的操作.本篇将使用M ...

  3. WPF播放器

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

  4. WPF技术触屏上的应用系列(四): 3D效果图片播放器(图片立体轮放、图片立体轮播、图片倒影立体滚动)效果实现

    原文:WPF技术触屏上的应用系列(四): 3D效果图片播放器(图片立体轮放.图片立体轮播.图片倒影立体滚动)效果实现 去年某客户单位要做个大屏触屏应用,要对档案资源进行展示之用.客户端是Window7 ...

  5. HTML5播放器 MediaElement.js 使用方法

    目前已经有很多html5播放器可以使用,使用html5播放器可以轻松的在页面中插入媒体视频,从而使我们的web页面变得更加丰富多彩,所以今 天向大家推荐一款非常优秀的html5播放器MediaElem ...

  6. 将WPF版的弹幕播放器给优化了一下

    年前较闲的时候研究了一下WPF的性能优化,练手的时将之前写的弹幕播放器给重新写了一下.年前的时间不大够,没有写完,这两天接着弄了一下,基本上弄得差不多了. 主要重写了底层的渲染算法,优化后效果还是非常 ...

  7. 用WPF写了一个弹幕播放器

    看弹幕视频的时候,如果不发弹幕,一个本地的弹幕播放器往往能带来更好的体验.目前已经有一些实现了,最初用过一个MukioPlayer, 后来又用过一个用C++写的BiliLocal,这个程序能自动下载弹 ...

  8. 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 简易音乐播放器主界面设计 - .NET CORE(C#) WPF开发 阅读导航 本文背景 代码 ...

  9. 基于ffmpeg网络播放器的教程与总结

    基于ffmpeg网络播放器的教程与总结   一.         概述 为了解决在线无广告播放youku网上的视频.(youku把每个视频切换成若干个小视频). 视频资源解析可以从www.flvcd. ...

随机推荐

  1. Lucene.Net 2.3.1开发介绍 —— 三、索引(五)

    原文:Lucene.Net 2.3.1开发介绍 -- 三.索引(五) 话接上篇,继续来说权重对排序的影响.从上面的4个测试,只能说是有个直观的理解了.“哦,是!调整权重是能影响排序了,但是好像没办法来 ...

  2. 基于MMSeg算法的中文分词类库

    原文:基于MMSeg算法的中文分词类库 最近在实现基于lucene.net的搜索方案,涉及中文分词,找了很多,最终选择了MMSeg4j,但MMSeg4j只有Java版,在博客园上找到了*王员外*(ht ...

  3. form表单和表格

    HTML <table> 标签 border pixels 规定表格边框的宽度. STF cellpadding pixels % 规定单元边沿与其内容之间的空白. STF cellspa ...

  4. flashcache中应用device mapper机制

    Device Mapper(DM)是Linux 2.6全面引入的块设备新构架,通过DM可以灵活地管理系统中所有的真实或虚拟的块设备. DM以块设备的形式注册到Linux内核中,凡是挂载(或者说“映射” ...

  5. ibatis新手入门

    ibatis 是什么 iBATIS是以SQL为中心的持久化层框架. 能支持懒载入.关联查询.继承等特性. iBATIS不同于一般的OR映射框架. OR映射框架,将数据库表.字段等映射到类.属性,那是一 ...

  6. 站在OC的基础上快速理解Swift的类与结构体

    阅读此文章前,您已经有一定的Object-C语法基础了!) 2014年,Apple推出了Swift,最近开始应用到实际的项目中. 首先我发现在编写Swift代码的时候,经常会遇到Xcode不能提示,卡 ...

  7. 文件比较,文件夹比较-- vimdiff,beyond compare, compare suite, WinMerge,Kdiff3

    文件比较,文件夹比较-- vimdiff,beyond compare, compare suite, WinMerge,Kdiff3  有一个项目的源码包需要比较,400M以上,这就要找个好的工具了 ...

  8. Common lisp菜鸟指南(译)

    Common lisp菜鸟指南(译) Common lisp菜鸟指南(译)

  9. VC6迁移到VS2008几个问题——良好的代码,从我做起,从现在开始。

    最近.有一个项目开发,需要使用一次项目的代码.只有当项目VC6下编译通过的,在VS2008下不一定编译通过,能编译通过也不一定能链接成功.以下总结一下我在一个VC6项目移植到VS2008中遇到的一些问 ...

  10. hdu1171(DP求两份物品的价值相差最小)

    题目信息: 给出一些物品的价值和个数.分成两份,是这两份的价值相差最小(DP方法) http://acm.hdu.edu.cn/showproblem.php? pid=1171 AC代码: /** ...